답안 #121075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121075 2019-06-26T04:47:19 Z 김세빈(#2968) Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
114 ms 162976 KB
#include <bits/stdc++.h>

using namespace std;

char S[444];
int dp[444][444][444][3];
int R[444], G[444], Y[444];
int RG[444], RY[444], GY[444], GR[444], YR[444], YG[444];
int n, r, g, y;

int main()
{
	int i, j, k;

	scanf("%d%s", &n, S);

	for(i=0; i<n; i++){
		if(S[i] == 'R') RG[++r] = g ,RY[r] = y;
		else if(S[i] == 'G') GY[++g] = y, GR[g] = r;
		else YR[++y] = r, YG[y] = g;
	}

	for(i=0; i<=r; i++){
		for(j=0; j<=g; j++){
			for(k=0; k<=y; k++){
				dp[i][j][k][0] = i? min(dp[i - 1][j][k][1], dp[i - 1][j][k][2]) + max(0, RG[i] - j) + max(0, RY[i] - k) : (i + j + k != 0) * 1e9;
				dp[i][j][k][1] = j? min(dp[i][j - 1][k][2], dp[i][j - 1][k][0]) + max(0, GY[j] - k) + max(0, GR[j] - i) : (i + j + k != 0) * 1e9;
				dp[i][j][k][2] = k? min(dp[i][j][k - 1][0], dp[i][j][k - 1][1]) + max(0, YR[k] - i) + max(0, YG[k] - j) : (i + j + k != 0) * 1e9;
			}
		}
	}

	k = min(min(dp[r][g][y][0], dp[r][g][y][1]), dp[r][g][y][2]);
	printf("%d\n", k < 1e9? k : -1);

	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:15: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 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 11 ms 512 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 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 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 11 ms 512 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 2432 KB Output is correct
19 Correct 3 ms 2048 KB Output is correct
20 Correct 3 ms 2304 KB Output is correct
21 Correct 4 ms 2432 KB Output is correct
22 Correct 3 ms 1652 KB Output is correct
23 Correct 3 ms 2176 KB Output is correct
24 Correct 3 ms 1664 KB Output is correct
25 Correct 5 ms 3968 KB Output is correct
26 Correct 4 ms 4224 KB Output is correct
27 Correct 3 ms 3072 KB Output is correct
28 Correct 3 ms 2432 KB Output is correct
29 Correct 3 ms 2304 KB Output is correct
30 Correct 3 ms 2304 KB Output is correct
31 Correct 3 ms 2048 KB Output is correct
32 Correct 3 ms 2432 KB Output is correct
33 Correct 4 ms 3840 KB Output is correct
34 Correct 4 ms 3584 KB Output is correct
35 Correct 3 ms 2688 KB Output is correct
36 Correct 3 ms 1920 KB Output is correct
37 Correct 3 ms 1792 KB Output is correct
38 Correct 3 ms 2176 KB Output is correct
39 Correct 3 ms 2304 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 3 ms 2176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 109 ms 162808 KB Output is correct
3 Correct 109 ms 162040 KB Output is correct
4 Correct 110 ms 162808 KB Output is correct
5 Correct 109 ms 162808 KB Output is correct
6 Correct 114 ms 162936 KB Output is correct
7 Correct 108 ms 162108 KB Output is correct
8 Correct 113 ms 162168 KB Output is correct
9 Correct 110 ms 161272 KB Output is correct
10 Correct 106 ms 162832 KB Output is correct
11 Correct 112 ms 162976 KB Output is correct
12 Correct 32 ms 44024 KB Output is correct
13 Correct 54 ms 77176 KB Output is correct
14 Correct 74 ms 111352 KB Output is correct
15 Correct 112 ms 162808 KB Output is correct
16 Correct 110 ms 162876 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 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 11 ms 512 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 2432 KB Output is correct
19 Correct 3 ms 2048 KB Output is correct
20 Correct 3 ms 2304 KB Output is correct
21 Correct 4 ms 2432 KB Output is correct
22 Correct 3 ms 1652 KB Output is correct
23 Correct 3 ms 2176 KB Output is correct
24 Correct 3 ms 1664 KB Output is correct
25 Correct 5 ms 3968 KB Output is correct
26 Correct 4 ms 4224 KB Output is correct
27 Correct 3 ms 3072 KB Output is correct
28 Correct 3 ms 2432 KB Output is correct
29 Correct 3 ms 2304 KB Output is correct
30 Correct 3 ms 2304 KB Output is correct
31 Correct 3 ms 2048 KB Output is correct
32 Correct 3 ms 2432 KB Output is correct
33 Correct 4 ms 3840 KB Output is correct
34 Correct 4 ms 3584 KB Output is correct
35 Correct 3 ms 2688 KB Output is correct
36 Correct 3 ms 1920 KB Output is correct
37 Correct 3 ms 1792 KB Output is correct
38 Correct 3 ms 2176 KB Output is correct
39 Correct 3 ms 2304 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 3 ms 2176 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 109 ms 162808 KB Output is correct
44 Correct 109 ms 162040 KB Output is correct
45 Correct 110 ms 162808 KB Output is correct
46 Correct 109 ms 162808 KB Output is correct
47 Correct 114 ms 162936 KB Output is correct
48 Correct 108 ms 162108 KB Output is correct
49 Correct 113 ms 162168 KB Output is correct
50 Correct 110 ms 161272 KB Output is correct
51 Correct 106 ms 162832 KB Output is correct
52 Correct 112 ms 162976 KB Output is correct
53 Correct 32 ms 44024 KB Output is correct
54 Correct 54 ms 77176 KB Output is correct
55 Correct 74 ms 111352 KB Output is correct
56 Correct 112 ms 162808 KB Output is correct
57 Correct 110 ms 162876 KB Output is correct
58 Correct 70 ms 83524 KB Output is correct
59 Correct 89 ms 105948 KB Output is correct
60 Correct 84 ms 96248 KB Output is correct
61 Correct 79 ms 93048 KB Output is correct
62 Correct 108 ms 160520 KB Output is correct
63 Correct 109 ms 160104 KB Output is correct
64 Correct 111 ms 150364 KB Output is correct
65 Correct 103 ms 138616 KB Output is correct
66 Correct 77 ms 94328 KB Output is correct
67 Correct 79 ms 90804 KB Output is correct
68 Correct 81 ms 97184 KB Output is correct
69 Correct 79 ms 93660 KB Output is correct
70 Correct 80 ms 101496 KB Output is correct
71 Correct 79 ms 92024 KB Output is correct
72 Correct 33 ms 42488 KB Output is correct
73 Correct 5 ms 3200 KB Output is correct