제출 #41202

#제출 시각아이디문제언어결과실행 시간메모리
41202IvanC수열 (BOI14_sequence)C++14
34 / 100
1068 ms1004 KiB
#include <bits/stdc++.h>
using namespace std;
random_device rd;
knuth_b gen(rd());
const int MAXN = 1e5 + 10;
int K,vetor[MAXN],freq[10][2];
int pretest[20];
int check(int ini){
	for(int i = ini,ptr = 1;ptr <= K;i++,ptr++){
		if(i == 0 && vetor[ptr] == 0) continue;
		int copia = i;
		while(copia != 0 && copia % 10 != vetor[ptr]) copia /= 10;
		if(copia == 0) return 0;
	}
	return 1;
}
int pretesting(int ini){
	for(int j = 0;j<19;j++){
		int ptr = pretest[j];
		int i = vetor[ptr];
		if(i == 0 && vetor[ptr] == 0) continue;
		int copia = i;
		while(copia != 0 && copia % 10 != vetor[ptr]) copia /= 10;
		if(copia == 0) return 0;
	}
	return 1;
}
int main(){	
	cin >> K;
	for(int i = 1;i<=K;i++){
		cin >> vetor[i];
		freq[vetor[i]][1]++;
	}
	for(int i = 0;i<19;i++){
		int aleatorio = 1 + (gen() % K);
		pretest[i] = aleatorio;
	}
	if(K <= 1000){
		for(int i = 1;i<=1000000;i++){
			if(!pretesting(i)) continue;
			if(check(i)){
				cout << i << endl;
				return 0;
			}
		}
	}
	if(vetor[1] == 9){
		int geratriz = 8;
		while(true){
			if(check(geratriz + 1)){
				cout << geratriz + 1 << endl;
				return 0;
			}
			geratriz *= 10;
			geratriz += 8;
		}
	}
	else if(vetor[1] == 0){
		int ini = 1;
		while(true){
			if(check(ini)){
				cout << ini << endl;
				return 0;
			}
			ini *= 10;
		}
	}
	else{
		int ini = vetor[1];
		while(true){
			if(check(ini)){
				cout << ini << endl;
				return 0;
			}
			ini *= 10;
		}
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...