#include<stdio.h>
int t,n;
int table[1000001],trace[1000001],number[1000001];
int min(int a,int b){return a<b?a:b;}
int main()
{
int i,m,k=8,j,a;
scanf("%d",&t);
trace[3]=trace[6]=3;
trace[5]=5;
trace[8]=8;
table[3]=table[5]=table[8]=1;
table[6]=2;
table[1]=table[2]=table[4]=table[7]=100;
for(a=0;a<t;a++)
{
scanf("%d",&n);
if(n==1||n==2||n==4||n==7)
{
printf("-1\n");
continue;
}
if(n>k)
{
for(i=k+1;i<=n;i++)
{
m=min(table[i-3],table[i-5]);
m=min(m,table[i-8]);
table[i]=m+1;
if(m==table[i-3])trace[i]=3;
if(m==table[i-5])trace[i]=5;
if(m==table[i-8])trace[i]=8;
}
k=n;
}
j=0;
for(i=n;i>0;)
{
number[j++]=trace[i];
i-=trace[i];
}
for(j--;j>=0;j--)printf("%d",number[j]);
printf("\n");
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
12604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
12604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
12604 KB |
Output is correct |
2 |
Correct |
0 ms |
12604 KB |
Output is correct |
3 |
Correct |
0 ms |
12604 KB |
Output is correct |
4 |
Correct |
0 ms |
12604 KB |
Output is correct |
5 |
Correct |
0 ms |
12604 KB |
Output is correct |
6 |
Correct |
0 ms |
12604 KB |
Output is correct |
7 |
Correct |
0 ms |
12604 KB |
Output is correct |
8 |
Correct |
0 ms |
12604 KB |
Output is correct |
9 |
Correct |
0 ms |
12604 KB |
Output is correct |
10 |
Correct |
0 ms |
12604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
652 ms |
12604 KB |
Output is correct |
2 |
Correct |
648 ms |
12604 KB |
Output is correct |
3 |
Correct |
693 ms |
12604 KB |
Output is correct |
4 |
Correct |
611 ms |
12604 KB |
Output is correct |
5 |
Correct |
681 ms |
12604 KB |
Output is correct |
6 |
Correct |
661 ms |
12604 KB |
Output is correct |
7 |
Correct |
697 ms |
12604 KB |
Output is correct |
8 |
Correct |
685 ms |
12604 KB |
Output is correct |
9 |
Correct |
706 ms |
12604 KB |
Output is correct |
10 |
Correct |
685 ms |
12604 KB |
Output is correct |
11 |
Correct |
659 ms |
12604 KB |
Output is correct |
12 |
Correct |
662 ms |
12604 KB |
Output is correct |
13 |
Correct |
684 ms |
12604 KB |
Output is correct |
14 |
Correct |
742 ms |
12604 KB |
Output is correct |
15 |
Correct |
656 ms |
12604 KB |
Output is correct |
16 |
Correct |
664 ms |
12604 KB |
Output is correct |
17 |
Correct |
651 ms |
12604 KB |
Output is correct |
18 |
Correct |
646 ms |
12604 KB |
Output is correct |
19 |
Correct |
748 ms |
12604 KB |
Output is correct |
20 |
Correct |
626 ms |
12604 KB |
Output is correct |
21 |
Correct |
656 ms |
12604 KB |
Output is correct |
22 |
Correct |
646 ms |
12604 KB |
Output is correct |
23 |
Correct |
632 ms |
12604 KB |
Output is correct |
24 |
Correct |
633 ms |
12604 KB |
Output is correct |
25 |
Correct |
639 ms |
12604 KB |
Output is correct |