Submission #1231611

#TimeUsernameProblemLanguageResultExecution timeMemory
1231611kaiboySequence (BOI14_sequence)C++20
9 / 100
559 ms416 KiB
#include <algorithm>
#include <iostream>

using namespace std;

const       int   N = 1000;
const       int   A = 100000;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;

int dd[N];

bool check(int a, int d) {
	for ( ; a; a /= 10)
		if (a % 10 == d)
			return true;
	return false;
}

bool check_(int a, int d) {
	return a < A / 10 && !d || check(a, d);
}

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> dd[i];
	for (int a = 1; a < A; a++) {
		bool yes = true;
		for (int i = 0; i < n; i++)
			if (!check(a + i, dd[i])) {
				yes = false;
				break;
			}
		if (yes) {
			cout << a << '\n';
			return 0;
		}
	}
	long long ans = INF;
	for (int a = 0; a < A - N; a++) {
		int b = 0;
		for (int i = 0; i < n; i++)
			if (!check_(a + i, dd[i]))
				b |= 1 << dd[i];
		if (!(b >> 1))
			b |= 1 << 1;
		long long x = 0;
		for (int d = 1; d < 10; d++)
			if (b >> d & 1)
				x = x * 10 + d;
		if (b & 1)
			x *= 10;
		x = x * A + a;
		ans = min(ans, x);
	}
	cout << ans << '\n';
	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...