답안 #121056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121056 2019-06-26T04:16:31 Z 윤지학(#2973) Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
38 ms 28668 KB
#include <cstdio>

char s[404];
int a[404], b[404], c[404];
int d[2424242][3];

inline int min(int x, int y) {
	return x < y ? x : y;
}

inline int abs(int x) {
	return x < 0 ? -x : x;
}

int main() {
	int x, y, z;
	int i, j, k, l, n;
	scanf("%d%s", &n, s);
	x = y = z = 0;
	for (i = 0; i < n; i++) {
		if (s[i] == 'R') ++x;
		if (s[i] == 'G') a[++y] = x;
		if (s[i] == 'Y') {
			++z;
			b[z] = x;
			c[z] = y;
		}
	}
	x++; y++; z++;
	for (i = 0; i < x; i++) for (j = 0; j < y; j++) for (k = 0; k < z; k++) {
		if (i + j + k == 0) continue;
		l = (i * y + j) * z + k;
		if (i) d[l][0] = min(d[l - y * z][1], d[l - y * z][2]);
		else d[l][0] = 1e9;
		if (j) d[l][1] = min(d[l - z][0], d[l - z][2]) + abs(a[j] - i);
		else d[l][1] = 1e9;
		if (k) d[l][2] = min(d[l - 1][0], d[l - 1][1]) + abs(b[k] - i) + abs(c[k] - j);
		else d[l][2] = 1e9;
	}
	l = x * y * z - 1;
	l = min(min(d[l][0], d[l][1]), d[l][2]);
	printf("%d\n", l < 1e9 ? l : -1);
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%s", &n, s);
  ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 256 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 2 ms 768 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 3 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 256 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 3 ms 768 KB Output is correct
44 Correct 3 ms 768 KB Output is correct
45 Correct 3 ms 768 KB Output is correct
46 Correct 3 ms 768 KB Output is correct
47 Correct 3 ms 768 KB Output is correct
48 Correct 2 ms 768 KB Output is correct
49 Correct 3 ms 768 KB Output is correct
50 Correct 2 ms 768 KB Output is correct
51 Correct 3 ms 768 KB Output is correct
52 Correct 3 ms 768 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 2 ms 640 KB Output is correct
56 Correct 2 ms 768 KB Output is correct
57 Correct 3 ms 768 KB Output is correct
58 Correct 36 ms 28372 KB Output is correct
59 Correct 35 ms 28416 KB Output is correct
60 Correct 35 ms 28280 KB Output is correct
61 Correct 34 ms 28560 KB Output is correct
62 Correct 5 ms 2564 KB Output is correct
63 Correct 7 ms 4352 KB Output is correct
64 Correct 19 ms 14208 KB Output is correct
65 Correct 26 ms 20352 KB Output is correct
66 Correct 34 ms 28152 KB Output is correct
67 Correct 35 ms 28152 KB Output is correct
68 Correct 38 ms 28536 KB Output is correct
69 Correct 36 ms 28664 KB Output is correct
70 Correct 35 ms 28668 KB Output is correct
71 Correct 35 ms 28060 KB Output is correct
72 Correct 10 ms 7424 KB Output is correct
73 Correct 4 ms 2176 KB Output is correct