#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)
{
c=0; p=1;
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>=dap/w) return;
c*=w; c+=num;
if(c==num && 1&a[0]) c=w*10+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++)
{
r=a[j];
s[(i+j)/10]|=a[j]&(1023-(1<<((i+j)%10)));
}
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 |
0 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 |
Incorrect |
0 ms |
1240 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
0 ms |
1240 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1240 KB |
Output is correct |
2 |
Correct |
32 ms |
1240 KB |
Output is correct |
3 |
Incorrect |
28 ms |
1240 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
244 ms |
1580 KB |
Output is correct |
6 |
Correct |
0 ms |
1240 KB |
Output is correct |
7 |
Incorrect |
0 ms |
1240 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |