#include<stdio.h>
int d[100001];
long long getAns(int data[], const int n, int depth)
{
int *arg;
long long ans = 102345678900000000ll;
if(n==1 || depth > 6)
{
for(int i=2; i<=n; i++) data[1] |= data[i];
ans = 0;
int c = 0;
if(data[1] % 2 == 1)
{
if(data[1] == 1) return 10;
else
{
int i;
for(i=1; i<=9; i++)
{
if(((data[1] >> i) & 1) == 1)
{
ans = i*10;
break;
}
}
for(i++; i<=9; i++) if(((data[1] >> i) & 1) == 1) ans = ans * 10 + i;
return ans;
}
}
else
{
for(int i=0; i<=9; i++) if(((data[1] >> i) & 1) == 1) ans = ans * 10 + i;
return ans;
}
}
arg = new int[100001];
int start = 0, re = 10000;
for(start = 0; start<=9; start++)
{
int fd, N;
fd = start;
arg[N = 1] = 0;
for(int i=1; i<=n; i++)
{
arg[N] |= data[i] & (1023 - (1<<fd));
if(++fd == 10)
{
fd = 0;
arg[++N] = 0;
}
}
long long l = getAns(arg, N, depth + 1);
if(re > l*10 + start)
{
re = l*10 + start;
}
}
delete[] arg;
return re;
}
int main()
{
int n, i;
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%d", d+i);
}
/*if(d[1] == 0)
{
for(i=2; i<=n; i++)
{
int N = i-1;
while(N)
{
if(N%10 == d[i]) break;
N/=10;
}
if(N==0) break;
}
if(i==n+1)
{
printf("0");
return 0;
}
}*/
for(i=1; i<=n; i++)
{
d[i] = 1<<d[i];
}
long long ans = getAns(d, n, 1);
printf("%lld", ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3944 KB |
Output is correct |
2 |
Correct |
12 ms |
3944 KB |
Output is correct |
3 |
Correct |
4 ms |
3944 KB |
Output is correct |
4 |
Correct |
8 ms |
3944 KB |
Output is correct |
5 |
Correct |
0 ms |
3944 KB |
Output is correct |
6 |
Incorrect |
4 ms |
3944 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3944 KB |
Output is correct |
2 |
Correct |
16 ms |
3944 KB |
Output is correct |
3 |
Correct |
0 ms |
3944 KB |
Output is correct |
4 |
Correct |
0 ms |
3944 KB |
Output is correct |
5 |
Correct |
0 ms |
3944 KB |
Output is correct |
6 |
Incorrect |
4 ms |
3944 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1596 KB |
Output is correct |
2 |
Incorrect |
52 ms |
3944 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3944 KB |
Output is correct |
2 |
Correct |
0 ms |
3944 KB |
Output is correct |
3 |
Correct |
16 ms |
3944 KB |
Output is correct |
4 |
Correct |
0 ms |
3944 KB |
Output is correct |
5 |
Incorrect |
76 ms |
3944 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |