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>
int B[250][3]; //[0]:3,[1]:5,[2]:8
int s[250],N;
bool ch[250];
int main()
{
int i,j,k;
for(i=0;i<=80;i++){
for(j=0;3*i+5*j<=240;j++){
for(k=0;3*i+5*j+8*k<=240;k++){
int x=3*i+5*j+8*k;
if(!ch[x]){ch[x]=1;s[x]=i+j+k;B[x][0]=i;B[x][1]=j;B[x][2]=k;continue;}
if(s[x]>i+j+k || s[x]==i+j+k&&B[x][0]<i){
s[x]=i+j+k;B[x][0]=i;B[x][1]=j;B[x][2]=k;
}
}
}
}
int t;scanf("%d",&t);
while(t--){
scanf("%d",&N);
if(N==1 || N==2 || N==4 || N==7){printf("-1\n");continue;}
if(N<=240){
for(i=1;i<=B[N][0];i++)printf("3");
for(i=1;i<=B[N][1];i++)printf("5");
for(i=1;i<=B[N][2];i++)printf("8");
printf("\n");
continue;
}
int t=N%120+120;
for(i=1;i<=B[t][0];i++)printf("3");
for(i=1;i<=B[t][1];i++)printf("5");
for(i=1;i<=B[t][2]+(N/120)*15-15;i++)printf("8");
printf("\n");
}
return 0;
}
# | 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... |