#include <iostream>
using namespace std;
int d[1000001],a[1000001],s[1000001],sp;
int main()
{
int t,n,l,i,j,k,c;
int birth_num[3]={3,5,8};
cin >> t;
for(l=1;l<=t;l++){
cin >> n;
for(i=0;i<=n;i++) d[i]=999999;
for(i=0;i<3;i++){
k=birth_num[i];
d[k]=1; a[k]=k;
for(j=k+1;j<=n;j++){
if(d[j-k]==999999)continue;
if(d[j-k]+1<d[j]){
d[j]=d[j-k]+1;
a[j]=k;
}
else if(d[j-k]+1==d[j]){
if(j-k<j-a[j]){
d[j]=d[j-k]+1;
a[j]=k;
}
}
}
}
if(d[n]==999999) cout << "-1" << endl;
else{
sp=0;
c=n;
while(c>0){
sp++;
s[sp]=a[c];
c=c-a[c];
}
for(i=sp;i>=1;i--) cout << s[i];
cout << endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
13096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
13096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
13096 KB |
Output is correct |
2 |
Correct |
0 ms |
13096 KB |
Output is correct |
3 |
Correct |
0 ms |
13096 KB |
Output is correct |
4 |
Correct |
1 ms |
13096 KB |
Output is correct |
5 |
Correct |
1 ms |
13096 KB |
Output is correct |
6 |
Correct |
0 ms |
13096 KB |
Output is correct |
7 |
Correct |
0 ms |
13096 KB |
Output is correct |
8 |
Correct |
0 ms |
13096 KB |
Output is correct |
9 |
Correct |
0 ms |
13096 KB |
Output is correct |
10 |
Correct |
0 ms |
13096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
735 ms |
13096 KB |
Output is correct |
2 |
Correct |
758 ms |
13096 KB |
Output is correct |
3 |
Correct |
798 ms |
13096 KB |
Output is correct |
4 |
Correct |
737 ms |
13096 KB |
Output is correct |
5 |
Correct |
770 ms |
13096 KB |
Output is correct |
6 |
Correct |
751 ms |
13096 KB |
Output is correct |
7 |
Correct |
818 ms |
13096 KB |
Output is correct |
8 |
Correct |
816 ms |
13096 KB |
Output is correct |
9 |
Correct |
830 ms |
13096 KB |
Output is correct |
10 |
Correct |
802 ms |
13096 KB |
Output is correct |
11 |
Correct |
759 ms |
13096 KB |
Output is correct |
12 |
Correct |
780 ms |
13096 KB |
Output is correct |
13 |
Correct |
778 ms |
13096 KB |
Output is correct |
14 |
Correct |
868 ms |
13096 KB |
Output is correct |
15 |
Correct |
763 ms |
13096 KB |
Output is correct |
16 |
Correct |
752 ms |
13096 KB |
Output is correct |
17 |
Correct |
748 ms |
13096 KB |
Output is correct |
18 |
Correct |
749 ms |
13096 KB |
Output is correct |
19 |
Correct |
864 ms |
13096 KB |
Output is correct |
20 |
Correct |
724 ms |
13096 KB |
Output is correct |
21 |
Correct |
770 ms |
13096 KB |
Output is correct |
22 |
Correct |
750 ms |
13096 KB |
Output is correct |
23 |
Correct |
735 ms |
13096 KB |
Output is correct |
24 |
Correct |
736 ms |
13096 KB |
Output is correct |
25 |
Correct |
744 ms |
13096 KB |
Output is correct |