#include<stdio.h>
int d[100001];
long long getAns(int d[], int n, int dep)
{
int i, start;
int *arg;
long long ans = 10234567890000000ll;
if(n==1 || dep > 6)
{
for(i=2; i<=n; i++)d[1] |= d[i];
if(d[1] == 1) return 10;
if(d[1] %2 == 1)
{
for(i=1; i<=9; i++) if((d[1] >> i)%2 == 1)
{
ans = i*10;
break;
}
for(i++; i<=9; i++) if((d[1] >> i)%2 == 1) ans = ans*10 + i;
return ans;
}
else
{
ans = 0;
for(i=1; i<=9; i++) if((d[1] >> i)%2 == 1) ans = ans*10 + i;
return ans;
}
}
arg = new int[n/10+50];
int fd = 0, N = 1;
arg[1] = 0;
for(i=1; i<=n; i++)
{
if(fd == 10)
{
arg[++N] = 0;
fd = 0;
}
if(i == 1)
{
if(d[i] != 0) break;
}
else
{
if( (d[i] & (~(1<<fd))) != 0 ) break;
}
fd++;
}
if(i==n+1) return 0;
for(start = 0; start<=9; start++)
{
fd = start;
arg[N=1] = 0;
for(i=1; i<=n; i++)
{
if(fd == 10)
{
arg[++N] = 0;
fd = 0;
}
arg[N] |= d[i]&(~(1<<fd));
fd++;
}
for(i=1; i<=N; i++) if(arg[i] != 0) break;
if(i==N+1)
{
if(start != 0) { if(ans > start) ans = start; }
else if(ans > 10) ans = 10;
}
else
{
long long l;
if(start == 0) l = getAns(arg, N, dep+1);
else l = getAns(arg, N, dep+1);
if(ans > l*10 + start) ans = l*10 + start;
}
}
delete[] arg;
return ans;
}
int main()
{
int n, i;
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%d", d+i);
d[i] = 1<<d[i];
}
printf("%lld", getAns(d, n, 1));
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1600 KB |
Output is correct |
2 |
Correct |
0 ms |
1600 KB |
Output is correct |
3 |
Correct |
0 ms |
1600 KB |
Output is correct |
4 |
Correct |
0 ms |
1600 KB |
Output is correct |
5 |
Correct |
0 ms |
1600 KB |
Output is correct |
6 |
Correct |
0 ms |
1600 KB |
Output is correct |
7 |
Correct |
0 ms |
1600 KB |
Output is correct |
8 |
Correct |
0 ms |
1600 KB |
Output is correct |
9 |
Correct |
0 ms |
1600 KB |
Output is correct |
10 |
Correct |
0 ms |
1600 KB |
Output is correct |
11 |
Correct |
0 ms |
1600 KB |
Output is correct |
12 |
Correct |
0 ms |
1600 KB |
Output is correct |
13 |
Correct |
0 ms |
1600 KB |
Output is correct |
14 |
Correct |
0 ms |
1600 KB |
Output is correct |
15 |
Correct |
0 ms |
1600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1600 KB |
Output is correct |
2 |
Correct |
0 ms |
1600 KB |
Output is correct |
3 |
Correct |
0 ms |
1600 KB |
Output is correct |
4 |
Correct |
0 ms |
1600 KB |
Output is correct |
5 |
Correct |
0 ms |
1600 KB |
Output is correct |
6 |
Correct |
0 ms |
1600 KB |
Output is correct |
7 |
Correct |
0 ms |
1600 KB |
Output is correct |
8 |
Correct |
0 ms |
1600 KB |
Output is correct |
9 |
Correct |
0 ms |
1600 KB |
Output is correct |
10 |
Correct |
0 ms |
1600 KB |
Output is correct |
11 |
Correct |
0 ms |
1600 KB |
Output is correct |
12 |
Correct |
0 ms |
1600 KB |
Output is correct |
13 |
Correct |
0 ms |
1600 KB |
Output is correct |
14 |
Correct |
0 ms |
1600 KB |
Output is correct |
15 |
Correct |
0 ms |
1600 KB |
Output is correct |
16 |
Correct |
0 ms |
1600 KB |
Output is correct |
17 |
Correct |
0 ms |
1600 KB |
Output is correct |
18 |
Correct |
0 ms |
1600 KB |
Output is correct |
19 |
Correct |
0 ms |
1600 KB |
Output is correct |
20 |
Correct |
0 ms |
1600 KB |
Output is correct |
21 |
Correct |
0 ms |
1600 KB |
Output is correct |
22 |
Correct |
0 ms |
1600 KB |
Output is correct |
23 |
Correct |
0 ms |
1600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1600 KB |
Output is correct |
2 |
Correct |
8 ms |
1600 KB |
Output is correct |
3 |
Correct |
8 ms |
1600 KB |
Output is correct |
4 |
Correct |
4 ms |
1600 KB |
Output is correct |
5 |
Correct |
4 ms |
1600 KB |
Output is correct |
6 |
Correct |
8 ms |
1600 KB |
Output is correct |
7 |
Correct |
44 ms |
1600 KB |
Output is correct |
8 |
Correct |
32 ms |
1600 KB |
Output is correct |
9 |
Correct |
60 ms |
1600 KB |
Output is correct |
10 |
Correct |
60 ms |
1600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1600 KB |
Output is correct |
2 |
Correct |
0 ms |
1600 KB |
Output is correct |
3 |
Correct |
0 ms |
1600 KB |
Output is correct |
4 |
Correct |
0 ms |
1600 KB |
Output is correct |
5 |
Correct |
32 ms |
1600 KB |
Output is correct |
6 |
Correct |
0 ms |
1600 KB |
Output is correct |
7 |
Correct |
0 ms |
1600 KB |
Output is correct |
8 |
Correct |
0 ms |
1600 KB |
Output is correct |
9 |
Correct |
0 ms |
1600 KB |
Output is correct |
10 |
Correct |
0 ms |
1600 KB |
Output is correct |
11 |
Correct |
60 ms |
1600 KB |
Output is correct |
12 |
Correct |
64 ms |
1600 KB |
Output is correct |
13 |
Correct |
0 ms |
1600 KB |
Output is correct |
14 |
Correct |
0 ms |
1600 KB |
Output is correct |
15 |
Correct |
0 ms |
1600 KB |
Output is correct |
16 |
Correct |
0 ms |
1600 KB |
Output is correct |
17 |
Correct |
0 ms |
1600 KB |
Output is correct |
18 |
Correct |
0 ms |
1600 KB |
Output is correct |
19 |
Correct |
0 ms |
1600 KB |
Output is correct |
20 |
Correct |
0 ms |
1600 KB |
Output is correct |
21 |
Correct |
0 ms |
1600 KB |
Output is correct |
22 |
Correct |
0 ms |
1600 KB |
Output is correct |
23 |
Correct |
0 ms |
1600 KB |
Output is correct |
24 |
Correct |
0 ms |
1600 KB |
Output is correct |
25 |
Correct |
0 ms |
1600 KB |
Output is correct |
26 |
Correct |
0 ms |
1600 KB |
Output is correct |
27 |
Correct |
8 ms |
1600 KB |
Output is correct |
28 |
Correct |
4 ms |
1600 KB |
Output is correct |
29 |
Correct |
4 ms |
1600 KB |
Output is correct |
30 |
Correct |
4 ms |
1600 KB |
Output is correct |
31 |
Correct |
8 ms |
1600 KB |
Output is correct |
32 |
Correct |
44 ms |
1600 KB |
Output is correct |
33 |
Correct |
32 ms |
1600 KB |
Output is correct |
34 |
Correct |
56 ms |
1600 KB |
Output is correct |
35 |
Correct |
64 ms |
1600 KB |
Output is correct |
36 |
Correct |
52 ms |
1600 KB |
Output is correct |
37 |
Correct |
68 ms |
1600 KB |
Output is correct |
38 |
Correct |
40 ms |
1600 KB |
Output is correct |
39 |
Correct |
72 ms |
1600 KB |
Output is correct |
40 |
Correct |
68 ms |
1600 KB |
Output is correct |