답안 #20129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20129 2016-02-27T09:25:08 Z hongjun7 생일수 I (GA4_birthday1) C++14
100 / 100
692 ms 16708 KB
#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("");
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 16708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 16708 KB Output is correct
2 Correct 14 ms 16708 KB Output is correct
3 Correct 7 ms 16708 KB Output is correct
4 Correct 14 ms 16708 KB Output is correct
5 Correct 13 ms 16708 KB Output is correct
6 Correct 14 ms 16708 KB Output is correct
7 Correct 14 ms 16708 KB Output is correct
8 Correct 14 ms 16708 KB Output is correct
9 Correct 8 ms 16708 KB Output is correct
10 Correct 10 ms 16708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 692 ms 16708 KB Output is correct
2 Correct 600 ms 16708 KB Output is correct
3 Correct 665 ms 16708 KB Output is correct
4 Correct 653 ms 16708 KB Output is correct
5 Correct 626 ms 16708 KB Output is correct
6 Correct 669 ms 16708 KB Output is correct
7 Correct 571 ms 16708 KB Output is correct
8 Correct 632 ms 16708 KB Output is correct
9 Correct 660 ms 16708 KB Output is correct
10 Correct 618 ms 16708 KB Output is correct
11 Correct 598 ms 16708 KB Output is correct
12 Correct 577 ms 16708 KB Output is correct
13 Correct 635 ms 16708 KB Output is correct
14 Correct 625 ms 16708 KB Output is correct
15 Correct 598 ms 16708 KB Output is correct
16 Correct 630 ms 16708 KB Output is correct
17 Correct 650 ms 16708 KB Output is correct
18 Correct 590 ms 16708 KB Output is correct
19 Correct 631 ms 16708 KB Output is correct
20 Correct 551 ms 16708 KB Output is correct
21 Correct 622 ms 16708 KB Output is correct
22 Correct 640 ms 16708 KB Output is correct
23 Correct 626 ms 16708 KB Output is correct
24 Correct 659 ms 16708 KB Output is correct
25 Correct 662 ms 16708 KB Output is correct