25812023-01-17 17:43:49kohumarkSzivárványszámokcpp11Time limit exceeded 2/45400ms22472 KiB
#include <iostream>
#include <string>
#include <set>
using namespace std;

string x;
int counter=0;
set<string> sol;

bool small(string act){
	if(act.length()<x.length()) return true;
	else if(act.length()==x.length()){
		for(int i=0; i<(int)x.length(); i++){
			if(x[i]<act[i]) return false;
			if(i==(int)x.length()-1&&act[i]==x[i]) return false;
		}
		return true;
	}
	return false;
}

void calc(string l, string r, string max){
	string now=l+max+r;
	if(small(now)&&!sol.count(now)){
		counter++;
		sol.insert(now);
		if(now.length()<x.length()){
			for(int i=1; i<stoi(max.substr(0,1)); i++){
				if((int)l.length()==0) calc(to_string(i),r,max);
				else{
					bool first=true;
					for(int j=i; j<stoi(max.substr(0,1)); j++){
						if(l.find(to_string(j))!=string::npos){
							first=false;
							calc(l.substr(0,l.find(to_string(j)))+to_string(i)+l.substr(l.find(to_string(j))),r,max);
							break;
						}
					}
					if(first){
						calc(l+to_string(i),r,max);
					}
				}
			}
			for(int i=0; i<stoi(max.substr(0,1)); i++){
				if((int)r.length()==0) calc(l,to_string(i),max);
				else{
					bool first=true;
					for(int j=i; j>=0; j--){
						if(r.find(to_string(j))!=string::npos){
							first=false;
							calc(l,r.substr(0,r.find(to_string(j)))+to_string(i)+r.substr(r.find(to_string(j))),max);
							break;
						}
					}
					if(first){
						calc(l,r+to_string(i),max);
					}
				}
			}
			calc(l,r,max+max[0]);
		}
	}
}

int main(){
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	cin >> x;
	
	
	if(x!="0") counter++;
	if((int)x.length()>1) for(int i=1; i<10; i++) calc("","",to_string(i));
	else for(int i=1; i<stoi(x); i++) calc("","",to_string(i));
	
	cout << counter;
	//string act; cin >> act; cout << small(act);
}
 
SubtaskSumTestVerdictTimeMemory
base2/45
1Accepted0/04ms1880 KiB
2Time limit exceeded0/0400ms10348 KiB
3Time limit exceeded0/0351ms16756 KiB
4Accepted1/12ms2248 KiB
5Wrong answer0/12ms2456 KiB
6Wrong answer0/14ms2588 KiB
7Wrong answer0/14ms2596 KiB
8Wrong answer0/119ms3292 KiB
9Wrong answer0/120ms3340 KiB
10Accepted1/193ms5612 KiB
11Wrong answer0/196ms5980 KiB
12Wrong answer0/193ms5812 KiB
13Time limit exceeded0/2368ms9968 KiB
14Time limit exceeded0/2367ms9848 KiB
15Time limit exceeded0/2361ms8720 KiB
16Time limit exceeded0/2367ms8640 KiB
17Time limit exceeded0/1342ms9032 KiB
18Time limit exceeded0/2400ms20240 KiB
19Time limit exceeded0/2358ms19024 KiB
20Time limit exceeded0/2375ms21608 KiB
21Time limit exceeded0/3368ms22036 KiB
22Time limit exceeded0/2374ms13608 KiB
23Time limit exceeded0/2358ms13332 KiB
24Time limit exceeded0/2361ms13356 KiB
25Time limit exceeded0/2342ms19872 KiB
26Time limit exceeded0/2375ms21880 KiB
27Time limit exceeded0/2363ms21504 KiB
28Time limit exceeded0/2367ms21596 KiB
29Time limit exceeded0/2377ms22472 KiB
30Time limit exceeded0/2365ms22092 KiB