#include <stdio.h>
#include <algorithm>
#define ffs(a) __builtin_ffs(a)
using namespace std;
typedef long long LL;
int a[18][100010];
LL dfs(int p,int A[],int an,int w){
int i,j,k,v,z;
LL mn=102345678900000L;
if(an==1){
if(A[0]<=1)return A[0]*10;
v=A[0]&1022;
mn=(ffs(v)-1)*(A[0]&1? 10:1);
for(v-=v&-v;v;v-=v&-v)mn=mn*10+ffs(v)-1;
return mn;
}
for(i=0;i<=9-w;++i){
k=i,v=z=0;
int *B=a[p+1],bn=0;
for(j=0;j<an;++j){
v|=A[j]^(A[j]&(1<<k));
if(A[j]&1&&!k)z=1;
k=(k+1)%10;
if(!k||j+1==an){
B[bn++]=v;
v=0;
}
}
LL rv=dfs(p+1,B,bn,i==9&&an<=2)*10+i;
if(!rv&&z)rv=10;
mn=min(mn,rv);
}
return mn;
}
int main(){
int i,k,an=0,v;
scanf("%d",&k);
for(i=1;i<=k;++i){
scanf("%d",&v);
a[0][an++]=1<<v;
}
printf("%lld",dfs(0,a[0],an,0));
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
8116 KB |
Output is correct |
2 |
Correct |
0 ms |
8116 KB |
Output is correct |
3 |
Correct |
0 ms |
8116 KB |
Output is correct |
4 |
Correct |
0 ms |
8116 KB |
Output is correct |
5 |
Correct |
0 ms |
8116 KB |
Output is correct |
6 |
Correct |
0 ms |
8116 KB |
Output is correct |
7 |
Correct |
0 ms |
8116 KB |
Output is correct |
8 |
Correct |
0 ms |
8116 KB |
Output is correct |
9 |
Correct |
0 ms |
8116 KB |
Output is correct |
10 |
Correct |
0 ms |
8116 KB |
Output is correct |
11 |
Correct |
0 ms |
8116 KB |
Output is correct |
12 |
Correct |
0 ms |
8116 KB |
Output is correct |
13 |
Correct |
0 ms |
8116 KB |
Output is correct |
14 |
Correct |
0 ms |
8116 KB |
Output is correct |
15 |
Correct |
1 ms |
8116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
8116 KB |
Output is correct |
2 |
Correct |
0 ms |
8116 KB |
Output is correct |
3 |
Correct |
0 ms |
8116 KB |
Output is correct |
4 |
Correct |
0 ms |
8116 KB |
Output is correct |
5 |
Correct |
0 ms |
8116 KB |
Output is correct |
6 |
Correct |
0 ms |
8116 KB |
Output is correct |
7 |
Correct |
0 ms |
8116 KB |
Output is correct |
8 |
Correct |
0 ms |
8116 KB |
Output is correct |
9 |
Correct |
0 ms |
8116 KB |
Output is correct |
10 |
Correct |
0 ms |
8116 KB |
Output is correct |
11 |
Correct |
0 ms |
8116 KB |
Output is correct |
12 |
Correct |
0 ms |
8116 KB |
Output is correct |
13 |
Correct |
0 ms |
8116 KB |
Output is correct |
14 |
Correct |
0 ms |
8116 KB |
Output is correct |
15 |
Correct |
0 ms |
8116 KB |
Output is correct |
16 |
Correct |
0 ms |
8116 KB |
Output is correct |
17 |
Correct |
0 ms |
8116 KB |
Output is correct |
18 |
Correct |
0 ms |
8116 KB |
Output is correct |
19 |
Correct |
0 ms |
8116 KB |
Output is correct |
20 |
Correct |
0 ms |
8116 KB |
Output is correct |
21 |
Correct |
0 ms |
8116 KB |
Output is correct |
22 |
Correct |
0 ms |
8116 KB |
Output is correct |
23 |
Correct |
0 ms |
8116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
8116 KB |
Output is correct |
2 |
Correct |
9 ms |
8116 KB |
Output is correct |
3 |
Correct |
9 ms |
8116 KB |
Output is correct |
4 |
Correct |
9 ms |
8116 KB |
Output is correct |
5 |
Correct |
6 ms |
8116 KB |
Output is correct |
6 |
Correct |
6 ms |
8116 KB |
Output is correct |
7 |
Correct |
56 ms |
8116 KB |
Output is correct |
8 |
Correct |
37 ms |
8116 KB |
Output is correct |
9 |
Correct |
79 ms |
8116 KB |
Output is correct |
10 |
Correct |
79 ms |
8116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
8116 KB |
Output is correct |
2 |
Correct |
0 ms |
8116 KB |
Output is correct |
3 |
Correct |
0 ms |
8116 KB |
Output is correct |
4 |
Correct |
0 ms |
8116 KB |
Output is correct |
5 |
Correct |
54 ms |
8116 KB |
Output is correct |
6 |
Correct |
0 ms |
8116 KB |
Output is correct |
7 |
Correct |
0 ms |
8116 KB |
Output is correct |
8 |
Correct |
1 ms |
8116 KB |
Output is correct |
9 |
Correct |
0 ms |
8116 KB |
Output is correct |
10 |
Correct |
1 ms |
8116 KB |
Output is correct |
11 |
Correct |
78 ms |
8116 KB |
Output is correct |
12 |
Correct |
78 ms |
8116 KB |
Output is correct |
13 |
Correct |
0 ms |
8116 KB |
Output is correct |
14 |
Correct |
0 ms |
8116 KB |
Output is correct |
15 |
Correct |
1 ms |
8116 KB |
Output is correct |
16 |
Correct |
0 ms |
8116 KB |
Output is correct |
17 |
Correct |
0 ms |
8116 KB |
Output is correct |
18 |
Correct |
0 ms |
8116 KB |
Output is correct |
19 |
Correct |
1 ms |
8116 KB |
Output is correct |
20 |
Correct |
2 ms |
8116 KB |
Output is correct |
21 |
Correct |
0 ms |
8116 KB |
Output is correct |
22 |
Correct |
0 ms |
8116 KB |
Output is correct |
23 |
Correct |
1 ms |
8116 KB |
Output is correct |
24 |
Correct |
0 ms |
8116 KB |
Output is correct |
25 |
Correct |
0 ms |
8116 KB |
Output is correct |
26 |
Correct |
1 ms |
8116 KB |
Output is correct |
27 |
Correct |
6 ms |
8116 KB |
Output is correct |
28 |
Correct |
6 ms |
8116 KB |
Output is correct |
29 |
Correct |
9 ms |
8116 KB |
Output is correct |
30 |
Correct |
9 ms |
8116 KB |
Output is correct |
31 |
Correct |
7 ms |
8116 KB |
Output is correct |
32 |
Correct |
49 ms |
8116 KB |
Output is correct |
33 |
Correct |
33 ms |
8116 KB |
Output is correct |
34 |
Correct |
80 ms |
8116 KB |
Output is correct |
35 |
Correct |
78 ms |
8116 KB |
Output is correct |
36 |
Correct |
82 ms |
8116 KB |
Output is correct |
37 |
Correct |
116 ms |
8116 KB |
Output is correct |
38 |
Correct |
69 ms |
8116 KB |
Output is correct |
39 |
Correct |
119 ms |
8116 KB |
Output is correct |
40 |
Correct |
121 ms |
8116 KB |
Output is correct |