#include<stdio.h>
int d[100001];
long long getAns(int data[], const int n, int depth, bool prevZero)
{
//printf("%d %d %d \n", n, data[1], data[2]);
int *arg;
long long ans = 102345678900000000ll;
int i;
for(i=1; i<=n; i++) if(data[i] != 0) break;
if(i==n+1 && !prevZero) return 0;
if(n==1 || depth > 6)
{
for(i=2; i<=n; i++) data[1] |= data[i];
ans = 0;
int c = 0;
if(data[1] == 0 && prevZero)
{
return 1;
}
else if(data[1] == 0)
{
return 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=1; i<=9; i++) if(((data[1] >> i) & 1) == 1) ans = ans * 10 + i;
return ans;
}
}
arg = new int[n/10+100];
int start = 0;
for(start = 0; start<=9; start++)
{
int fd, N;
fd = start;
arg[N = 1] = 0;
for(int i=1; i<=n; i++)
{
if(fd == 10)
{
fd = 0;
arg[++N] = 0;
}
arg[N] = arg[N] | (data[i] & (~(1<<fd)) );
fd++;
}
long long l;
//printf("Call %d %d %d %d %d\n", N, depth+1, arg[1], arg[2], start);
for(i=1; i<=N; i++) if(arg[i] != 0) break;
if(i==N+1 && start == 0 && !prevZero) return 0;
else if(start == 0) l = getAns(arg, N, depth + 1, true);
else l = getAns(arg, N, depth+1, false);
//printf("Log %d %d %d %d %lld %d\n", N, depth+1, arg[1], arg[2], l, start);
if(ans > l*10 + start)
{
ans = l*10 + start;
//printf("Ans %lld\n", ans);
}
}
delete[] arg;
return ans;
}
int main()
{
int n, i;
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%d", d+i);
}
for(i=1; i<=n; i++)
{
d[i] = 1<<d[i];
}
long long ans = getAns(d, n, 1, true);
printf("%lld", ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1596 KB |
Output is correct |
2 |
Correct |
0 ms |
1596 KB |
Output is correct |
3 |
Correct |
0 ms |
1596 KB |
Output is correct |
4 |
Correct |
0 ms |
1596 KB |
Output is correct |
5 |
Correct |
0 ms |
1596 KB |
Output is correct |
6 |
Correct |
0 ms |
1596 KB |
Output is correct |
7 |
Correct |
0 ms |
1596 KB |
Output is correct |
8 |
Incorrect |
0 ms |
1596 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1596 KB |
Output is correct |
2 |
Correct |
0 ms |
1596 KB |
Output is correct |
3 |
Correct |
0 ms |
1596 KB |
Output is correct |
4 |
Correct |
0 ms |
1596 KB |
Output is correct |
5 |
Correct |
0 ms |
1596 KB |
Output is correct |
6 |
Correct |
0 ms |
1596 KB |
Output is correct |
7 |
Correct |
0 ms |
1596 KB |
Output is correct |
8 |
Correct |
0 ms |
1596 KB |
Output is correct |
9 |
Incorrect |
0 ms |
1596 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1596 KB |
Output is correct |
2 |
Correct |
12 ms |
1596 KB |
Output is correct |
3 |
Correct |
12 ms |
1596 KB |
Output is correct |
4 |
Incorrect |
8 ms |
6084 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1596 KB |
Output is correct |
2 |
Correct |
0 ms |
1596 KB |
Output is correct |
3 |
Correct |
0 ms |
1596 KB |
Output is correct |
4 |
Correct |
0 ms |
1596 KB |
Output is correct |
5 |
Correct |
32 ms |
1596 KB |
Output is correct |
6 |
Correct |
0 ms |
1596 KB |
Output is correct |
7 |
Correct |
0 ms |
1596 KB |
Output is correct |
8 |
Correct |
0 ms |
1596 KB |
Output is correct |
9 |
Correct |
0 ms |
1596 KB |
Output is correct |
10 |
Incorrect |
0 ms |
1596 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |