#include<cstdio>
#include<vector>
std::vector<int> a;
long long min;
void f(int w,std::vector<int> x,int y,int z)
{
if(w>5)
{
int i,j=0;
long long k;
for(i=0;i<x.size();i++)j|=x[i];
if(j&1)
{
for(i=1;i<10;i++)if((j>>i)&1)break;
if(i==10)i=1;
k=i*10;
while(++i<10)if((j>>i)&1)k=k*10+i;
}
else
{
k=0;
for(i=1;i<10;i++)if((j>>i)&1)k=k*10+i;
}
if(k*z+y<min)min=k*z+y;
return;
}
int i,j,k;
for(j=0;j<x.size();j++)if(x[j])break;
if(j==x.size())
{
if(y<z/10)y+=z;
if(y<min)min=y;
return;
}
for(i=0;i<10;i++)
{
std::vector<int> t;
k=0;
for(j=0;j<x.size();j++)
{
k|=x[j]&~(1<<((i+j)%10));
if((i+j)%10==9)
{
t.push_back(k);
k=0;
}
}
if((i+j)%10)t.push_back(k);
f(w+1,t,y+i*z,z*10);
}
}
int main()
{
int i,n,t;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&t);
a.push_back(1<<t);
}
min=1e18;
f(0,a,0,1);
printf("%lld",min);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
1236 KB |
Output is correct |
2 |
Incorrect |
180 ms |
1236 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
1236 KB |
Output is correct |
2 |
Incorrect |
164 ms |
1236 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
1236 KB |
Output is correct |
2 |
Correct |
160 ms |
1236 KB |
Output is correct |
3 |
Correct |
184 ms |
1236 KB |
Output is correct |
4 |
Incorrect |
176 ms |
1236 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
1236 KB |
Output is correct |
2 |
Incorrect |
176 ms |
1236 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |