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 inf 0x7fffffff
int T, N[101], D[1000001], Limit, three[1000001], five[1000001], eight[1000001];
void input(void)
{
int i;
scanf("%d",&T);
for(i=1 ; i<=T ; i++)
{
scanf("%d",&N[i]);
if(Limit<N[i])
Limit=N[i];
}
}
void process(void)
{
int i, mmin, v;
D[1]=D[2]=D[4]=D[7]=inf;
D[3]=D[5]=D[6]=1;
three[3]=five[5]=1;
three[6]=2;
for(i=8 ; i<=Limit ; i++)
{
mmin=D[i-3];
v=3;
if(mmin>D[i-5])
{
v=5;
mmin=D[i-5];
}
if(mmin>D[i-8])
{
v=8;
mmin=D[i-8];
}
if(mmin==inf)
D[i]=inf;
else
{
D[i]=mmin+1;
if(v==3)
{
three[i]=three[i-3]+1;
five[i]=five[i-3];
eight[i]=eight[i-3];
}
else if(v==5)
{
three[i]=three[i-5];
five[i]=five[i-5]+1;
eight[i]=eight[i-5];
}
else
{
three[i]=three[i-8];
five[i]=five[i-8];
eight[i]=eight[i-8]+1;
}
}
}
}
void output(void)
{
int i, j;
for(i=1 ; i<=T ; i++)
{
if(D[N[i]]==inf)
printf("-1");
else
{
for(j=1 ; j<=three[N[i]] ; j++)
printf("3");
for(j=1 ; j<=five[N[i]] ; j++)
printf("5");
for(j=1 ; j<=eight[N[i]] ; j++)
printf("8");
printf("\n");
}
}
}
int main(void)
{
input();
process();
output();
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... |