Submission #2152

#TimeUsernameProblemLanguageResultExecution timeMemory
2152mhkim4886생일수 I (GA4_birthday1)C++98
33 / 100
1 ms8700 KiB
#include <stdio.h> typedef struct _Num { long long num; int total; } Num; long long out[101], n, qrear = 1, qtail = 1; Num que[500001]; int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { int k; scanf("%d", &k); qrear = 1; qtail = 4; que[1].num = que[1].total = 3; que[2].num = que[2].total = 5; que[3].num = que[3].total = 8; while(true) { int q = que[qrear++].total; if(q == k) { out[i] = que[qrear-1].num; break; } else { long long p = que[qrear-1].num % 10; if(que[qrear-1].total + 3 <= k && p <= 3) { que[qtail].num = que[qrear-1].num * 10 + 3; que[qtail++].total = que[qrear-1].total + 3; } if(que[qrear-1].total + 5 <= k && p <= 5) { que[qtail].num = que[qrear-1].num * 10 + 5; que[qtail++].total = que[qrear-1].total + 5; } if(que[qrear-1].total + 8 <= k && p <= 8) { 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("%lld\n", out[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...