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>
#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-5]==1||d[j-8]==1) d[j]=1;
else continue;
}
if(d[m]==0){printf("%d",-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);
f[3]=0; f[8]=0;f[5]=0;
}
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... |