Submission #1126608

#TimeUsernameProblemLanguageResultExecution timeMemory
1126608Halym2007Sequence (BOI14_sequence)C++17
9 / 100
1095 ms484 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz size()
#define ff first
#define ss second
#define pb push_back
#define pii pair <int, int>
#define dur exit(0)
#define dur1 return(0)
const int N = 2e5 + 5;
char a[N];
int main () {
//	freopen ("input.txt", "r", stdin);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	bool subtask = 0;
	for (int i = 1; i <= n; ++i) {
		int x;
		cin >> x;
		a[i] = char(x + 48);
		if (i > 1) {
			if (a[i - 1] != a[i]) subtask = 1;
		}
	}
	if (!subtask) {
//		cout << a[1];
//		return 0;
		if (a[1] == '9') {
			int cyk = 9, ayyr = 0, jog = 1;
			for (int i = 2; ; ++i) {
				jog *= 10;
				ayyr *= 10;
				ayyr++;
				cyk *= 10;
				if (jog + ayyr >= n) {
					break;
				}
			} 
			cout << cyk - ayyr;
		}
		else {
			if (a[1] != '0') cout << a[1];
			else cout << 1;
			if (a[1] != '0' and n == 1) return 0;
			int jog = 1;
			for (int i = 2; ; ++i) {
				jog *= 10;
				cout << 0;
				if (jog >= n) {
					break;
				}
			}
		}
		return 0;
	}
	else {
		for (int i = 1; ; ++i) {
			int idx = 0, bol = 0;
			for (int j = i; j <= i + n - 1; ++j) {
				string jog = to_string(j);
				idx++;
				int ok = 0; 
				for (char k : jog) {
					if (k == a[idx]) {
						ok = 1;
						break;
					}
				}	
				if (!ok) {
					bol = 1;
					break;
				}
			}
			if (!bol) {
				return cout << i, 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...