Submission #121076

# Submission time Handle Problem Language Result Execution time Memory
121076 2019-06-26T04:48:21 Z 김세빈(#2968) Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
112 ms 162824 KB
#include <bits/stdc++.h>

using namespace std;

char S[444];
int dp[444][444][444][3];
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:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%s", &n, S);
  ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 2 ms 512 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 5 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 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory 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 2 ms 512 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 5 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 512 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 1920 KB Output is correct
20 Correct 3 ms 2304 KB Output is correct
21 Correct 3 ms 2432 KB Output is correct
22 Correct 3 ms 1792 KB Output is correct
23 Correct 3 ms 2176 KB Output is correct
24 Correct 3 ms 1792 KB Output is correct
25 Correct 4 ms 3972 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 2304 KB Output is correct
29 Correct 3 ms 2304 KB Output is correct
30 Correct 4 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 3968 KB Output is correct
34 Correct 5 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 1764 KB Output is correct
38 Correct 3 ms 2176 KB Output is correct
39 Correct 4 ms 2304 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 3 ms 2348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 111 ms 162776 KB Output is correct
3 Correct 109 ms 162168 KB Output is correct
4 Correct 107 ms 162808 KB Output is correct
5 Correct 112 ms 162776 KB Output is correct
6 Correct 108 ms 162824 KB Output is correct
7 Correct 108 ms 162056 KB Output is correct
8 Correct 109 ms 162064 KB Output is correct
9 Correct 109 ms 161272 KB Output is correct
10 Correct 108 ms 162808 KB Output is correct
11 Correct 107 ms 162808 KB Output is correct
12 Correct 31 ms 44152 KB Output is correct
13 Correct 53 ms 77148 KB Output is correct
14 Correct 75 ms 111352 KB Output is correct
15 Correct 105 ms 162808 KB Output is correct
16 Correct 107 ms 162808 KB Output is correct
# Verdict Execution time Memory 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 2 ms 512 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 5 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 512 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 1920 KB Output is correct
20 Correct 3 ms 2304 KB Output is correct
21 Correct 3 ms 2432 KB Output is correct
22 Correct 3 ms 1792 KB Output is correct
23 Correct 3 ms 2176 KB Output is correct
24 Correct 3 ms 1792 KB Output is correct
25 Correct 4 ms 3972 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 2304 KB Output is correct
29 Correct 3 ms 2304 KB Output is correct
30 Correct 4 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 3968 KB Output is correct
34 Correct 5 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 1764 KB Output is correct
38 Correct 3 ms 2176 KB Output is correct
39 Correct 4 ms 2304 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 3 ms 2348 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 111 ms 162776 KB Output is correct
44 Correct 109 ms 162168 KB Output is correct
45 Correct 107 ms 162808 KB Output is correct
46 Correct 112 ms 162776 KB Output is correct
47 Correct 108 ms 162824 KB Output is correct
48 Correct 108 ms 162056 KB Output is correct
49 Correct 109 ms 162064 KB Output is correct
50 Correct 109 ms 161272 KB Output is correct
51 Correct 108 ms 162808 KB Output is correct
52 Correct 107 ms 162808 KB Output is correct
53 Correct 31 ms 44152 KB Output is correct
54 Correct 53 ms 77148 KB Output is correct
55 Correct 75 ms 111352 KB Output is correct
56 Correct 105 ms 162808 KB Output is correct
57 Correct 107 ms 162808 KB Output is correct
58 Correct 72 ms 83496 KB Output is correct
59 Correct 86 ms 105872 KB Output is correct
60 Correct 77 ms 96248 KB Output is correct
61 Correct 79 ms 93048 KB Output is correct
62 Correct 111 ms 160456 KB Output is correct
63 Correct 106 ms 159992 KB Output is correct
64 Correct 107 ms 150312 KB Output is correct
65 Correct 102 ms 138628 KB Output is correct
66 Correct 80 ms 94360 KB Output is correct
67 Correct 75 ms 90860 KB Output is correct
68 Correct 77 ms 97144 KB Output is correct
69 Correct 75 ms 93688 KB Output is correct
70 Correct 84 ms 101416 KB Output is correct
71 Correct 77 ms 91972 KB Output is correct
72 Correct 33 ms 42488 KB Output is correct
73 Correct 5 ms 3072 KB Output is correct