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 MAXN 1000000
int T, n, d[MAXN + 5], x[3] = { 3,5,8 }, v[MAXN + 5][3];
int main() {
for (int i = 1; i <= MAXN; i++) d[i] = MAXN;
for (int i = 0; i < 3; i++) {
for (int j = x[i]; j <= MAXN; j++) {
if (d[j - x[i]] + 1 < d[j]) {
d[j] = d[j - x[i]] + 1;
for (int k = 0; k < 3; k++) v[j][k] = v[j - x[i]][k];
v[j][i]++;
}
else if (d[j - x[i]] + 1 == d[j]) {
bool ok = 1;
for (int k = 0; k < 3; k++) {
int aa = v[j - x[i]][k];
if (k == i) aa++;
int bb = v[j][k];
if (aa < bb) { ok = 0; break; }
if (aa > bb) break;
}
if (ok) {
for (int k = 0; k < 3; k++) v[j][k] = v[j - x[i]][k];
v[j][i]++;
}
}
}
}
for (scanf("%d", &T); T--; ) {
scanf("%d", &n);
if (d[n] == MAXN) puts("-1");
else {
for (int i = 0; i < 3; i++) for (int j = 1; j <= v[n][i]; j++) printf("%d", x[i]);
puts("");
}
}
}
# | 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... |