#include<stdio.h>
#include<vector>
using namespace std;
int r,n;
long long int dap=2147483647000000000000LL,c,p,arr[513];
void dfs(long long int num,vector<int>a,int n,long long int w)
{
int i,j;
if(num>=dap) return;
if(n==-1)
{
if(num<w) num+=w*10;
if(num==0) num=w*10;
if(dap>num)
{
dap=num;
}
return;
}
if(n==1)
{
c=0; p=1;
r=a[0];
for(i=1;i<=9;i++)
{
if((1<<i)&a[0])
{
c=c*10+i;
if(c<10 && 1&a[0]) c=c*10;
}
}
if(c==0 && 1&a[0]) c=10;
if(c>dap/w) return;
c*=w; c+=num;
if(c==0) c=w*10;
if(dap>c)
{
dap=c;
}
return;
}
for(i=0;i<=9;i++)
{
vector<int>s((i+n-1)/10+1);
int sw=0;
if(w==1 && i==6)
{
w=1;
}
if(w==10 && i==8)
{
w=10;
}
if(w==100 && i==8)
{
w=100;
}
for(j=0;j<n;j++)
{
r=a[j];
s[(i+j)/10]|=a[j]&(1023-(1<<((i+j)%10)));
if(s[(i+j)/10]) sw=1;
}
if(i==0 && a[0]==0 && sw==0)
{
if(dap>num) dap=num;
}
if(sw==0){dfs(i*w+num,s,-1,w); break;}
dfs(i*w+num,s,(i+n-1)/10+1,w*10);
}
}
int main()
{
int i;
scanf("%d",&n);
vector<int>a(n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
a[i]=(1<<a[i]);
}
dfs(0,a,n,1);
printf("%lld",dap);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1240 KB |
Output is correct |
2 |
Correct |
4 ms |
1240 KB |
Output is correct |
3 |
Correct |
0 ms |
1240 KB |
Output is correct |
4 |
Correct |
0 ms |
1240 KB |
Output is correct |
5 |
Correct |
0 ms |
1240 KB |
Output is correct |
6 |
Correct |
0 ms |
1240 KB |
Output is correct |
7 |
Correct |
0 ms |
1240 KB |
Output is correct |
8 |
Correct |
0 ms |
1240 KB |
Output is correct |
9 |
Correct |
0 ms |
1240 KB |
Output is correct |
10 |
Correct |
4 ms |
1240 KB |
Output is correct |
11 |
Correct |
0 ms |
1240 KB |
Output is correct |
12 |
Correct |
0 ms |
1240 KB |
Output is correct |
13 |
Correct |
0 ms |
1240 KB |
Output is correct |
14 |
Correct |
0 ms |
1240 KB |
Output is correct |
15 |
Correct |
0 ms |
1240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1240 KB |
Output is correct |
2 |
Correct |
4 ms |
1240 KB |
Output is correct |
3 |
Correct |
0 ms |
1240 KB |
Output is correct |
4 |
Correct |
0 ms |
1240 KB |
Output is correct |
5 |
Correct |
0 ms |
1240 KB |
Output is correct |
6 |
Correct |
0 ms |
1240 KB |
Output is correct |
7 |
Correct |
0 ms |
1240 KB |
Output is correct |
8 |
Correct |
0 ms |
1240 KB |
Output is correct |
9 |
Correct |
0 ms |
1240 KB |
Output is correct |
10 |
Correct |
0 ms |
1240 KB |
Output is correct |
11 |
Correct |
8 ms |
1240 KB |
Output is correct |
12 |
Correct |
4 ms |
1240 KB |
Output is correct |
13 |
Correct |
0 ms |
1240 KB |
Output is correct |
14 |
Correct |
0 ms |
1240 KB |
Output is correct |
15 |
Correct |
0 ms |
1240 KB |
Output is correct |
16 |
Correct |
0 ms |
1240 KB |
Output is correct |
17 |
Correct |
0 ms |
1240 KB |
Output is correct |
18 |
Correct |
0 ms |
1240 KB |
Output is correct |
19 |
Correct |
0 ms |
1240 KB |
Output is correct |
20 |
Correct |
12 ms |
1240 KB |
Output is correct |
21 |
Correct |
4 ms |
1240 KB |
Output is correct |
22 |
Correct |
12 ms |
1240 KB |
Output is correct |
23 |
Correct |
12 ms |
1240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1240 KB |
Output is correct |
2 |
Correct |
32 ms |
1240 KB |
Output is correct |
3 |
Correct |
32 ms |
1240 KB |
Output is correct |
4 |
Correct |
20 ms |
1240 KB |
Output is correct |
5 |
Correct |
20 ms |
1240 KB |
Output is correct |
6 |
Correct |
12 ms |
1240 KB |
Output is correct |
7 |
Correct |
128 ms |
1780 KB |
Output is correct |
8 |
Correct |
96 ms |
1596 KB |
Output is correct |
9 |
Correct |
176 ms |
2020 KB |
Output is correct |
10 |
Correct |
188 ms |
2020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1240 KB |
Output is correct |
2 |
Correct |
4 ms |
1240 KB |
Output is correct |
3 |
Correct |
0 ms |
1240 KB |
Output is correct |
4 |
Correct |
0 ms |
1240 KB |
Output is correct |
5 |
Correct |
268 ms |
1580 KB |
Output is correct |
6 |
Correct |
0 ms |
1240 KB |
Output is correct |
7 |
Correct |
0 ms |
1240 KB |
Output is correct |
8 |
Correct |
0 ms |
1240 KB |
Output is correct |
9 |
Correct |
0 ms |
1240 KB |
Output is correct |
10 |
Correct |
0 ms |
1240 KB |
Output is correct |
11 |
Correct |
332 ms |
2020 KB |
Output is correct |
12 |
Correct |
196 ms |
2020 KB |
Output is correct |
13 |
Correct |
0 ms |
1240 KB |
Output is correct |
14 |
Correct |
8 ms |
1240 KB |
Output is correct |
15 |
Correct |
4 ms |
1240 KB |
Output is correct |
16 |
Correct |
0 ms |
1240 KB |
Output is correct |
17 |
Correct |
0 ms |
1240 KB |
Output is correct |
18 |
Correct |
0 ms |
1240 KB |
Output is correct |
19 |
Correct |
0 ms |
1240 KB |
Output is correct |
20 |
Correct |
0 ms |
1240 KB |
Output is correct |
21 |
Correct |
0 ms |
1240 KB |
Output is correct |
22 |
Correct |
0 ms |
1240 KB |
Output is correct |
23 |
Correct |
12 ms |
1240 KB |
Output is correct |
24 |
Correct |
4 ms |
1240 KB |
Output is correct |
25 |
Correct |
12 ms |
1240 KB |
Output is correct |
26 |
Correct |
12 ms |
1240 KB |
Output is correct |
27 |
Correct |
32 ms |
1240 KB |
Output is correct |
28 |
Correct |
32 ms |
1240 KB |
Output is correct |
29 |
Correct |
20 ms |
1240 KB |
Output is correct |
30 |
Correct |
20 ms |
1240 KB |
Output is correct |
31 |
Correct |
12 ms |
1240 KB |
Output is correct |
32 |
Correct |
128 ms |
1780 KB |
Output is correct |
33 |
Correct |
96 ms |
1596 KB |
Output is correct |
34 |
Correct |
184 ms |
2020 KB |
Output is correct |
35 |
Correct |
188 ms |
2020 KB |
Output is correct |
36 |
Correct |
696 ms |
1804 KB |
Output is correct |
37 |
Correct |
880 ms |
2004 KB |
Output is correct |
38 |
Correct |
848 ms |
1684 KB |
Output is correct |
39 |
Execution timed out |
1000 ms |
2020 KB |
Program timed out |
40 |
Halted |
0 ms |
0 KB |
- |