#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int N = 1e5 + 10;
int n, a[N];
bitset<11> mark[10000009], mark1[10000009];
int main() {
ios:: sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int w = 1; w <= 20000000; w++) {
if (10000000 < w) {
string s = to_string(w);
for (auto e : s)
mark1[w - 10000000][e - '0'] = true;
}
string s = to_string(w);
for (auto e : s)
mark[w][e - '0'] = true;
}
for (int w = 1; w <= 10000000; w++) {
int cnt = w;
bool flag = true;
for (int i = 0; i < n; i++) {
if (i) cnt++;
if (!mark[cnt][a[i]]) {
flag = false;
break;
}
}
if (flag) {
cout << w << '\n';
return 0;
}
}
for (int w = 1000001; w <= 20000000; w++) {
int cnt = w;
bool flag = true;
for (int i = 0; i < n; i++) {
if (i) cnt++;
if (!mark1[cnt - 1000000][a[i]]) {
flag = false;
break;
}
}
if (flag) {
cout << w << '\n';
return 0;
}
}
cout << -1 << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
257 ms |
160680 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
250 ms |
160748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
246 ms |
160792 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
244 ms |
160848 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |