#include <stdio.h>
#include <stdlib.h>
int d[1000001],f[9];
int main()
{
int n,m,i,j,kk,t=0,tt=0;
d[3]=1; d[0]=1; d[5]=1; d[8]=1;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&m);
kk=m;
for(j=1;j<=m;j++){
if(d[j-3]==1) d[j]=1;
else if(d[j-5]==1) d[j]=1;
else if(d[j-8]==1) d[j]=1;
}
if(d[m]==0){printf("%d\n",-1); continue;}
while(1){
if(d[kk-8]==1){f[8]+=1; kk=kk-8; }
else if(d[kk-5]==1){ f[5]+=1; kk=kk-5;}
else if(d[kk-3]==1){f[3]+=1; kk=kk-3;}
if(kk==0) break;
}
t=f[3]/4;
if(t>0&&f[8]>0){ f[3]=f[3]-t*4;f[8]=f[8]-t; f[5]=f[5]+t*4;}
for(j=1;j<=f[3];j++)printf("%d",3);
for(j=1;j<=f[5];j++)printf("%d",5);
for(j=1;j<=f[8];j++)printf("%d",8);
printf("\n");
f[3]=0; f[8]=0;f[5]=0;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4792 KB |
Output is correct |
2 |
Correct |
0 ms |
4792 KB |
Output is correct |
3 |
Correct |
0 ms |
4792 KB |
Output is correct |
4 |
Correct |
0 ms |
4792 KB |
Output is correct |
5 |
Correct |
0 ms |
4792 KB |
Output is correct |
6 |
Correct |
0 ms |
4792 KB |
Output is correct |
7 |
Correct |
0 ms |
4792 KB |
Output is correct |
8 |
Correct |
0 ms |
4792 KB |
Output is correct |
9 |
Correct |
0 ms |
4792 KB |
Output is correct |
10 |
Correct |
0 ms |
4792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
679 ms |
4792 KB |
Output is correct |
2 |
Correct |
672 ms |
4792 KB |
Output is correct |
3 |
Correct |
719 ms |
4792 KB |
Output is correct |
4 |
Correct |
633 ms |
4792 KB |
Output is correct |
5 |
Correct |
705 ms |
4792 KB |
Output is correct |
6 |
Correct |
688 ms |
4792 KB |
Output is correct |
7 |
Correct |
727 ms |
4792 KB |
Output is correct |
8 |
Correct |
727 ms |
4792 KB |
Output is correct |
9 |
Correct |
747 ms |
4792 KB |
Output is correct |
10 |
Correct |
712 ms |
4792 KB |
Output is correct |
11 |
Correct |
677 ms |
4792 KB |
Output is correct |
12 |
Correct |
699 ms |
4792 KB |
Output is correct |
13 |
Correct |
708 ms |
4792 KB |
Output is correct |
14 |
Correct |
761 ms |
4792 KB |
Output is correct |
15 |
Correct |
684 ms |
4792 KB |
Output is correct |
16 |
Correct |
694 ms |
4792 KB |
Output is correct |
17 |
Correct |
671 ms |
4792 KB |
Output is correct |
18 |
Correct |
673 ms |
4792 KB |
Output is correct |
19 |
Correct |
783 ms |
4792 KB |
Output is correct |
20 |
Correct |
688 ms |
4792 KB |
Output is correct |
21 |
Correct |
710 ms |
4792 KB |
Output is correct |
22 |
Correct |
699 ms |
4792 KB |
Output is correct |
23 |
Correct |
671 ms |
4792 KB |
Output is correct |
24 |
Correct |
681 ms |
4792 KB |
Output is correct |
25 |
Correct |
678 ms |
4792 KB |
Output is correct |