#include <bits/stdc++.h>
using namespace std;
long long mini = 1000000000000000000;
bool ok[1000001][10],num[10];
int n,arr[100001];
int func(int a , int b){
while(a){
if(a%10 == b){
return true;
}
a /= 10;
}
return false;
}
bool ok2(int val){
for(int i = 0 ; i < n ; i += 1){
if(!func(val+i,arr[i])){
return 0;
}
}
return 1;
}
int main(){
for(int i = 1 ; i <= 1000000 ; i += 1){
int j = i;
while(j){
ok[i][j%10] = 1;
j /= 10;
}
}
cin >> n;
set<int> st;
for(int i = 0 ; i < n ; i += 1){
cin >> arr[i];
st.insert(arr[i]);
}
if(st.size() == 1){
int val = max(arr[0],1);
while(true){
if(arr[0] == 9){
int v2 = 0 , vv = val;
while(vv){
v2 = (10*v2+8);
vv /= 10;
}
v2 += 1;
if(ok2(v2)){
cout << v2 << endl;
return 0;
}
}
if(ok2(val)){
cout << val << endl;
return 0;
}
val *= 10;
}
}
for(int i = 1 ; i <= 100000 ; i += 1){
int k = 1;
for(int j = 0 ; j < n ; j += 1){
if(!ok[i+j][arr[j]]){
k = 0;
break;
}
}
if(k){
cout << i << endl;
return 0;
}
}
for(int i = 1 ; i <= 100000 ; i += 1){
memset(num,0,sizeof num);
for(int j = 0 ; j < n ; j += 1){
if(!ok[i+j][arr[j]]){
num[arr[j]] = 1;
}
}
vector<int> v,v2;
for(int j = 0 ; j < 10 ; j += 1){
if(num[j]){
v.push_back(j);
}
}
sort(v.begin(),v.end());
if(v.size() == 1 && v[0] == 0){
continue;
}
int k = i;
for(int j = 0 ; j < 5 ; j += 1){
v2.push_back(k%10);
k /= 10;
}
reverse(v2.begin(),v2.end());
for(int j : v2){
v.push_back(j);
}
if(v[0] == 0){
swap(v[0],v[1]);
}
long long val = 0;
for(int j : v){
val = (10*val+j);
}
mini = min(mini,val);
}
cout << mini << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
10060 KB |
Output is correct |
2 |
Correct |
12 ms |
9984 KB |
Output is correct |
3 |
Correct |
12 ms |
10044 KB |
Output is correct |
4 |
Correct |
12 ms |
9988 KB |
Output is correct |
5 |
Correct |
12 ms |
9996 KB |
Output is correct |
6 |
Correct |
12 ms |
10060 KB |
Output is correct |
7 |
Correct |
12 ms |
10060 KB |
Output is correct |
8 |
Correct |
12 ms |
10004 KB |
Output is correct |
9 |
Correct |
12 ms |
9992 KB |
Output is correct |
10 |
Correct |
12 ms |
10060 KB |
Output is correct |
11 |
Correct |
12 ms |
10060 KB |
Output is correct |
12 |
Correct |
12 ms |
9992 KB |
Output is correct |
13 |
Correct |
12 ms |
10060 KB |
Output is correct |
14 |
Correct |
13 ms |
10060 KB |
Output is correct |
15 |
Correct |
12 ms |
9972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
9992 KB |
Output is correct |
2 |
Correct |
12 ms |
10060 KB |
Output is correct |
3 |
Correct |
14 ms |
10076 KB |
Output is correct |
4 |
Correct |
12 ms |
10012 KB |
Output is correct |
5 |
Correct |
13 ms |
10060 KB |
Output is correct |
6 |
Correct |
12 ms |
9968 KB |
Output is correct |
7 |
Correct |
12 ms |
9976 KB |
Output is correct |
8 |
Correct |
13 ms |
10088 KB |
Output is correct |
9 |
Correct |
13 ms |
10060 KB |
Output is correct |
10 |
Correct |
12 ms |
10016 KB |
Output is correct |
11 |
Correct |
438 ms |
10068 KB |
Output is correct |
12 |
Correct |
12 ms |
10060 KB |
Output is correct |
13 |
Correct |
13 ms |
9988 KB |
Output is correct |
14 |
Correct |
12 ms |
10064 KB |
Output is correct |
15 |
Correct |
12 ms |
10088 KB |
Output is correct |
16 |
Correct |
12 ms |
9972 KB |
Output is correct |
17 |
Correct |
13 ms |
10084 KB |
Output is correct |
18 |
Correct |
130 ms |
10060 KB |
Output is correct |
19 |
Correct |
224 ms |
10080 KB |
Output is correct |
20 |
Correct |
663 ms |
10080 KB |
Output is correct |
21 |
Correct |
213 ms |
10060 KB |
Output is correct |
22 |
Correct |
705 ms |
10064 KB |
Output is correct |
23 |
Correct |
706 ms |
10080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
10060 KB |
Output is correct |
2 |
Correct |
14 ms |
10220 KB |
Output is correct |
3 |
Correct |
14 ms |
10148 KB |
Output is correct |
4 |
Correct |
14 ms |
10144 KB |
Output is correct |
5 |
Correct |
14 ms |
10088 KB |
Output is correct |
6 |
Correct |
14 ms |
10060 KB |
Output is correct |
7 |
Correct |
25 ms |
10372 KB |
Output is correct |
8 |
Correct |
21 ms |
10348 KB |
Output is correct |
9 |
Correct |
30 ms |
10572 KB |
Output is correct |
10 |
Correct |
30 ms |
10632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
10060 KB |
Output is correct |
2 |
Correct |
21 ms |
9980 KB |
Output is correct |
3 |
Correct |
12 ms |
10060 KB |
Output is correct |
4 |
Correct |
12 ms |
10060 KB |
Output is correct |
5 |
Execution timed out |
1088 ms |
10188 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |