#include <iostream>
#include <vector>
int brute(const std::vector<int> &a) {
int have_digit[10][1001];
for (int d = 0; d < 10; ++d)
for (int w = 1; w <= 1000; w *= 10)
for (int i = d*w; i <= 1000; i += 10*w)
for (int j = i; j < i+w; ++j)
have_digit[d][j] = 1;
int n = 0;
bool ok;
do {
++n;
ok = true;
for (int i = 0; i < (int)a.size(); ++i)
ok &= have_digit[a[i]][n+i];
} while (!ok);
return n;
}
int main() {
std::cin.tie(0)->sync_with_stdio(0);
int k;
std::cin >> k;
std::vector<int> a(k);
for (int &x : a)
std::cin >> x;
int x = a[0];
bool all_same = true;
for (int i = 1; i < k; ++i)
all_same &= a[i] == x;
if (!all_same) {
std::cout << brute(a) << '\n';
return 0;
}
int v;
if (x == 0) {
v = 10;
int cnt = 1;
while (cnt < k) {
v = 10*v;
cnt = 10*cnt + 1;
}
} else if (x == 9) {
v = 9;
int cnt = 1;
while (cnt < k) {
v = 10*v - 1;
cnt = 10*cnt + 1;
}
} else {
v = x;
int cnt = 1;
while (cnt < k) {
v = 10*v;
cnt = 10*cnt;
}
}
std::cout << v << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Runtime error |
1 ms |
436 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
460 KB |
Output is correct |
9 |
Correct |
6 ms |
588 KB |
Output is correct |
10 |
Correct |
4 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |