Submission #121336

# Submission time Handle Problem Language Result Execution time Memory
121336 2019-06-26T10:50:22 Z onjo0127 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++11
100 / 100
195 ms 163164 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;
char S[409], C[4] = "RGY";
vector<int> T[3];
int P[3][409], D[409][409][409][3];

inline int its(int cn, int cc, int id) {
	return max(0, cc - P[cn][id]);
}

int go(int r, int g, int y, int x) {
	if(r+g+y == 0) return 0;
	int &ret = D[r][g][y][x];
	if(ret != -1) return ret;
	ret = INF;
	if(r && x == 0) ret = min(ret, min(go(r-1, g, y, 1), go(r-1, g, y, 2)) + its(1, g, T[0][r-1]) + its(2, y, T[0][r-1]));
	if(g && x == 1) ret = min(ret, min(go(r, g-1, y, 0), go(r, g-1, y, 2)) + its(0, r, T[1][g-1]) + its(2, y, T[1][g-1]));
	if(y && x == 2) ret = min(ret, min(go(r, g, y-1, 0), go(r, g, y-1, 1)) + its(0, r, T[2][y-1]) + its(1, g, T[2][y-1]));
	return ret;
}

int main() {
	int N; scanf("%d",&N);
	for(int i=1; i<=N; i++) {
		scanf(" %c",&S[i]);
		for(int j=0; j<3; j++) if(S[i] == C[j]) T[j].push_back(i);
	}
	for(int i=1; i<=N; i++) for(int j=0; j<3; j++) P[j][i] = P[j][i-1] + (S[i] == C[j]);
	for(int i=0; i<=P[0][N]; i++) for(int j=0; j<=P[1][N]; j++) for(int k=0; k<=P[2][N]; k++) for(int l=0; l<3; l++) D[i][j][k][l] = -1;
	int ans = INF;
	for(int i=0; i<3; i++) if(P[i][N]) ans = min(ans, go(P[0][N], P[1][N], P[2][N], i));
	if(ans == INF) puts("-1");
	else printf("%d", ans);
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N; scanf("%d",&N);
         ~~~~~^~~~~~~~~
joi2019_ho_t3.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c",&S[i]);
   ~~~~~^~~~~~~~~~~~~
# 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 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 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 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 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 4 ms 2304 KB Output is correct
19 Correct 4 ms 1920 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 1792 KB Output is correct
23 Correct 4 ms 2176 KB Output is correct
24 Correct 3 ms 1664 KB Output is correct
25 Correct 4 ms 3968 KB Output is correct
26 Correct 4 ms 4096 KB Output is correct
27 Correct 4 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 5 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 4 ms 2432 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 6 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 112 ms 162964 KB Output is correct
3 Correct 131 ms 162288 KB Output is correct
4 Correct 110 ms 163164 KB Output is correct
5 Correct 113 ms 163036 KB Output is correct
6 Correct 109 ms 163108 KB Output is correct
7 Correct 107 ms 162296 KB Output is correct
8 Correct 122 ms 162168 KB Output is correct
9 Correct 109 ms 161524 KB Output is correct
10 Correct 111 ms 163020 KB Output is correct
11 Correct 113 ms 163064 KB Output is correct
12 Correct 31 ms 44024 KB Output is correct
13 Correct 55 ms 77164 KB Output is correct
14 Correct 78 ms 111352 KB Output is correct
15 Correct 112 ms 163004 KB Output is correct
16 Correct 119 ms 163064 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 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 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 4 ms 2304 KB Output is correct
19 Correct 4 ms 1920 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 1792 KB Output is correct
23 Correct 4 ms 2176 KB Output is correct
24 Correct 3 ms 1664 KB Output is correct
25 Correct 4 ms 3968 KB Output is correct
26 Correct 4 ms 4096 KB Output is correct
27 Correct 4 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 5 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 4 ms 2432 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 6 ms 2304 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 112 ms 162964 KB Output is correct
44 Correct 131 ms 162288 KB Output is correct
45 Correct 110 ms 163164 KB Output is correct
46 Correct 113 ms 163036 KB Output is correct
47 Correct 109 ms 163108 KB Output is correct
48 Correct 107 ms 162296 KB Output is correct
49 Correct 122 ms 162168 KB Output is correct
50 Correct 109 ms 161524 KB Output is correct
51 Correct 111 ms 163020 KB Output is correct
52 Correct 113 ms 163064 KB Output is correct
53 Correct 31 ms 44024 KB Output is correct
54 Correct 55 ms 77164 KB Output is correct
55 Correct 78 ms 111352 KB Output is correct
56 Correct 112 ms 163004 KB Output is correct
57 Correct 119 ms 163064 KB Output is correct
58 Correct 195 ms 77116 KB Output is correct
59 Correct 174 ms 97656 KB Output is correct
60 Correct 170 ms 88796 KB Output is correct
61 Correct 160 ms 85752 KB Output is correct
62 Correct 108 ms 160744 KB Output is correct
63 Correct 111 ms 160312 KB Output is correct
64 Correct 119 ms 150256 KB Output is correct
65 Correct 140 ms 138616 KB Output is correct
66 Correct 191 ms 87128 KB Output is correct
67 Correct 175 ms 83832 KB Output is correct
68 Correct 165 ms 89808 KB Output is correct
69 Correct 161 ms 86428 KB Output is correct
70 Correct 169 ms 93656 KB Output is correct
71 Correct 172 ms 84956 KB Output is correct
72 Correct 33 ms 42076 KB Output is correct
73 Correct 4 ms 2944 KB Output is correct