#include<stdio.h>
#include<vector>
using namespace std;
int n,dap=2147483647,c,p,arr[513];
void dfs(int num,vector<int>a,int n,int w)
{
int i,j;
if(num>=dap) return;
if(n==1)
{
c=0; p=1;
for(i=0;i<=9;i++)
{
if((1<<i)&a[0])
{
c=c*10+i;
}
}
c*=w; c+=num;
if(dap>c)
{
dap=c;
}
return;
}
for(i=0;i<=9;i++)
{
vector<int>s((i+n-1)/10+1);
for(j=0;j<n;j++)
{
if(arr[a[j]]!=(i+j)%10) s[(i+j)/10]|=a[j];
}
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<=9;i++) arr[1<<i]=i;
for(i=0;i<n;i++){scanf("%d",&a[i]); a[i]=(1<<a[i]);}
dfs(0,a,n,1);
printf("%d",dap);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1240 KB |
Output is correct |
2 |
Incorrect |
0 ms |
1240 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1240 KB |
Output is correct |
2 |
Incorrect |
0 ms |
1240 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1240 KB |
Output is correct |
2 |
Incorrect |
0 ms |
1240 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |