#include <stdio.h>
typedef struct _Num
{
int num;
int total;
} Num;
int out[101], n, qrear = 1, qtail = 1;
Num que[100001];
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i++)
{
int k;
scanf("%d", &k);
qrear = 1;
qtail = 1;
que[qtail].num = que[qtail++].total = 3;
que[qtail].num = que[qtail++].total = 5;
que[qtail].num = que[qtail++].total = 8;
while(true)
{
int q = que[qrear++].total;
if(q == k)
{
out[i] = que[qrear-1].num;
break;
}
else
{
if(que[qrear-1].total + 3 <= k)
{
que[qtail].num = que[qrear-1].num * 10 + 3;
que[qtail++].total = que[qrear-1].total + 3;
}
if(que[qrear-1].total + 5 <= k)
{
que[qtail].num = que[qrear-1].num * 10 + 5;
que[qtail++].total = que[qrear-1].total + 5;
}
if(que[qrear-1].total + 8 <= k)
{
que[qtail].num = que[qrear-1].num * 10 + 8;
que[qtail++].total = que[qrear-1].total + 8;
}
}
if(qrear == qtail)
{
out[i] = -1;
break;
}
}
}
for(int i = 1; i <= n; i++) printf("%d\n", out[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
1664 KB |
SIGSEGV Segmentation fault |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
1664 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
1664 KB |
SIGSEGV Segmentation fault |
2 |
Halted |
0 ms |
0 KB |
- |