This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#define MX 1000001
int A[MX],B[3]={3,5,8},a,num[3];
int main(){
int i,j,n;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
A[0]=0;
for(i=1;i<MX;i++){A[i]=MX+1;}
for(i=1;i<MX;i++){
for(j=0;j<3;j++){
if(i>=B[j]&&(A[i-B[j]]+1)<A[i]){
A[i]=(A[i-B[j]]+1);
}
}
}
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a);
if(A[a]==MX+1){printf("-1\n");}
else{
for(j=0;j<3;j++){num[j]=0;}
for(j=a;j!=0;){
if(j>=8&&(A[j-8]+1)==A[j]){
num[2]++;
j-=8;\
}
else if(j>=5&&(A[j-5]+1)==A[j]){
num[1]++;
j-=5;
}
else{
num[0]++;
j-=3;
}
}
for(j=0;j<num[0];j++){printf("3");}
for(j=0;j<num[1];j++){printf("5");}
for(j=0;j<num[2];j++){printf("8");}
printf("\n");
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |