#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
typedef long long lld;
int N;
int A[MAXN];
lld dfs(vector<int> &arr, bool last_zero)
{
if (sz(arr) == 1){
lld ret = 0;
for (int i=1;i<10;i++) if (arr[0] & (1 << i)){
ret = ret*10 + i;
if ((arr[0] & 1) && ret) ret *= 10, arr[0] ^= 1;
}
if (arr[0] & 1) ret = ret ? ret*10 : 10;
return ret ? ret : last_zero;
}
lld ret = 123456789000000L;
for (int i=0;i<10;i++){
vector <int> nxt = {0};
int k = i;
for (int t: arr){
if (k == 10) k = 0, nxt.pb(0);
int &b = nxt[sz(nxt)-1];
b |= t ^ (t & (1 << k));
k++;
}
while (sz(arr) > 1 && !arr.back()) arr.pop_back();
if (sz(arr) == 2 && i == 9 && arr == nxt) continue;
ret = min(ret, dfs(nxt, i ? 0 : (arr[0] & 1)) * 10 + i);
}
return ret;
}
int main()
{
scanf("%d", &N);
for (int i=0;i<N;i++) scanf("%d", A+i);
vector <int> tmp;
for (int i=0;i<N;i++) tmp.pb(1 << A[i]);
lld ans = dfs(tmp, 1);
printf("%lld\n", ans ? ans : 10);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2112 KB |
Output is correct |
2 |
Correct |
1 ms |
2112 KB |
Output is correct |
3 |
Correct |
0 ms |
2112 KB |
Output is correct |
4 |
Correct |
0 ms |
2112 KB |
Output is correct |
5 |
Correct |
0 ms |
2112 KB |
Output is correct |
6 |
Correct |
0 ms |
2112 KB |
Output is correct |
7 |
Correct |
0 ms |
2112 KB |
Output is correct |
8 |
Correct |
2 ms |
2112 KB |
Output is correct |
9 |
Correct |
0 ms |
2112 KB |
Output is correct |
10 |
Correct |
0 ms |
2112 KB |
Output is correct |
11 |
Correct |
0 ms |
2112 KB |
Output is correct |
12 |
Correct |
0 ms |
2112 KB |
Output is correct |
13 |
Correct |
0 ms |
2112 KB |
Output is correct |
14 |
Correct |
0 ms |
2112 KB |
Output is correct |
15 |
Correct |
0 ms |
2112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2112 KB |
Output is correct |
2 |
Correct |
0 ms |
2112 KB |
Output is correct |
3 |
Correct |
0 ms |
2112 KB |
Output is correct |
4 |
Correct |
0 ms |
2112 KB |
Output is correct |
5 |
Correct |
0 ms |
2112 KB |
Output is correct |
6 |
Correct |
0 ms |
2112 KB |
Output is correct |
7 |
Correct |
0 ms |
2112 KB |
Output is correct |
8 |
Correct |
0 ms |
2112 KB |
Output is correct |
9 |
Correct |
0 ms |
2112 KB |
Output is correct |
10 |
Correct |
0 ms |
2112 KB |
Output is correct |
11 |
Correct |
2 ms |
2112 KB |
Output is correct |
12 |
Correct |
2 ms |
2112 KB |
Output is correct |
13 |
Correct |
2 ms |
2112 KB |
Output is correct |
14 |
Correct |
0 ms |
2112 KB |
Output is correct |
15 |
Correct |
0 ms |
2112 KB |
Output is correct |
16 |
Correct |
2 ms |
2112 KB |
Output is correct |
17 |
Correct |
2 ms |
2112 KB |
Output is correct |
18 |
Correct |
0 ms |
2112 KB |
Output is correct |
19 |
Correct |
1 ms |
2112 KB |
Output is correct |
20 |
Correct |
0 ms |
2112 KB |
Output is correct |
21 |
Correct |
0 ms |
2112 KB |
Output is correct |
22 |
Correct |
0 ms |
2112 KB |
Output is correct |
23 |
Correct |
0 ms |
2112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2112 KB |
Output is correct |
2 |
Correct |
22 ms |
2112 KB |
Output is correct |
3 |
Correct |
22 ms |
2112 KB |
Output is correct |
4 |
Correct |
21 ms |
2112 KB |
Output is correct |
5 |
Correct |
20 ms |
2112 KB |
Output is correct |
6 |
Correct |
11 ms |
2112 KB |
Output is correct |
7 |
Correct |
93 ms |
2884 KB |
Output is correct |
8 |
Correct |
91 ms |
2500 KB |
Output is correct |
9 |
Correct |
119 ms |
2884 KB |
Output is correct |
10 |
Correct |
128 ms |
2884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2112 KB |
Output is correct |
2 |
Correct |
0 ms |
2112 KB |
Output is correct |
3 |
Correct |
0 ms |
2112 KB |
Output is correct |
4 |
Correct |
0 ms |
2112 KB |
Output is correct |
5 |
Correct |
98 ms |
2500 KB |
Output is correct |
6 |
Correct |
0 ms |
2112 KB |
Output is correct |
7 |
Correct |
0 ms |
2112 KB |
Output is correct |
8 |
Correct |
2 ms |
2112 KB |
Output is correct |
9 |
Correct |
0 ms |
2112 KB |
Output is correct |
10 |
Correct |
0 ms |
2112 KB |
Output is correct |
11 |
Correct |
128 ms |
2884 KB |
Output is correct |
12 |
Correct |
203 ms |
2884 KB |
Output is correct |
13 |
Correct |
0 ms |
2112 KB |
Output is correct |
14 |
Correct |
0 ms |
2112 KB |
Output is correct |
15 |
Correct |
2 ms |
2112 KB |
Output is correct |
16 |
Correct |
2 ms |
2112 KB |
Output is correct |
17 |
Correct |
0 ms |
2112 KB |
Output is correct |
18 |
Correct |
0 ms |
2112 KB |
Output is correct |
19 |
Correct |
0 ms |
2112 KB |
Output is correct |
20 |
Correct |
0 ms |
2112 KB |
Output is correct |
21 |
Correct |
0 ms |
2112 KB |
Output is correct |
22 |
Correct |
0 ms |
2112 KB |
Output is correct |
23 |
Correct |
0 ms |
2112 KB |
Output is correct |
24 |
Correct |
0 ms |
2112 KB |
Output is correct |
25 |
Correct |
2 ms |
2112 KB |
Output is correct |
26 |
Correct |
0 ms |
2112 KB |
Output is correct |
27 |
Correct |
22 ms |
2112 KB |
Output is correct |
28 |
Correct |
22 ms |
2112 KB |
Output is correct |
29 |
Correct |
22 ms |
2112 KB |
Output is correct |
30 |
Correct |
20 ms |
2112 KB |
Output is correct |
31 |
Correct |
10 ms |
2112 KB |
Output is correct |
32 |
Correct |
91 ms |
2884 KB |
Output is correct |
33 |
Correct |
89 ms |
2500 KB |
Output is correct |
34 |
Correct |
127 ms |
2884 KB |
Output is correct |
35 |
Correct |
129 ms |
2884 KB |
Output is correct |
36 |
Correct |
161 ms |
2884 KB |
Output is correct |
37 |
Correct |
206 ms |
2884 KB |
Output is correct |
38 |
Correct |
129 ms |
2500 KB |
Output is correct |
39 |
Correct |
223 ms |
2884 KB |
Output is correct |
40 |
Correct |
211 ms |
2884 KB |
Output is correct |