Submission #272960

# Submission time Handle Problem Language Result Execution time Memory
272960 2020-08-19T00:15:57 Z ChrisT Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
374 ms 134904 KB
#include <bits/stdc++.h>
using namespace std;
void uin (int &a, int b) {
	if (b < a) a = b;
}
int main() {
	int n;
	scanf ("%d",&n);
	vector<vector<int>> pos(3), prep(3,vector<int>(n+1,n+1)); vector<int> done(3);
	for (int i = 1; i <= n; i++) {
		char ch; scanf (" %c",&ch); 
		int a = (ch == 'R' ? 0 : (ch == 'G' ? 1 : 2));
		pos[a].push_back(i);
	}
	for (int j = 0; j <= 2; j++) for (int i = n-1; i >= 1; i--) prep[j][i] = upper_bound(pos[j].begin(),pos[j].end(),i) - pos[j].begin() + 1;
	int a = (int)pos[0].size(), b = (int)pos[1].size(), c = (int)pos[2].size();
	vector<vector<vector<vector<int>>>> dp(a+1,vector<vector<vector<int>>>(b+1,vector<vector<int>>(c+1,vector<int>(3,1e9))));
    dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 0;
    for (done[0] = 0; done[0] <= a; done[0]++) {
		for (done[1] = 0; done[1] <= b; done[1]++) {
			for (done[2] = 0; done[2] <= c; done[2]++) if (done[0] || done[1] || done[2]){
				for (int take = 0; take <= 2; take++) if (done[take]) {
					int idx = pos[take][done[take]-1], add = 0;
					for (int j = 0; j <= 2; j++) if (j != take) {
						int big = prep[j][idx];
						add += max(0,done[j] - big + 1);
					}
					for (int lst = 0; lst <= 2; lst++) if (lst != take) {
						uin(dp[done[0]][done[1]][done[2]][take],dp[done[0]-(take==0)][done[1]-(take==1)][done[2]-(take==2)][lst] + add);
					}
				}
			}
		}
	}
	int ret = 1e9;
	for (int i = 0; i < 3; i++) uin(ret,dp[a][b][c][i]);
	printf ("%d\n",ret>1e8?-1:ret);
    return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |  scanf ("%d",&n);
      |  ~~~~~~^~~~~~~~~
joi2019_ho_t3.cpp:11:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |   char ch; scanf (" %c",&ch);
      |            ~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 288 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 2 ms 768 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 1 ms 768 KB Output is correct
23 Correct 2 ms 896 KB Output is correct
24 Correct 2 ms 768 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
28 Correct 2 ms 896 KB Output is correct
29 Correct 2 ms 896 KB Output is correct
30 Correct 2 ms 896 KB Output is correct
31 Correct 2 ms 768 KB Output is correct
32 Correct 2 ms 896 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 2 ms 768 KB Output is correct
36 Correct 2 ms 768 KB Output is correct
37 Correct 1 ms 768 KB Output is correct
38 Correct 2 ms 768 KB Output is correct
39 Correct 2 ms 896 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 7 ms 3840 KB Output is correct
3 Correct 7 ms 3840 KB Output is correct
4 Correct 7 ms 3840 KB Output is correct
5 Correct 7 ms 3840 KB Output is correct
6 Correct 7 ms 3840 KB Output is correct
7 Correct 7 ms 3840 KB Output is correct
8 Correct 9 ms 3840 KB Output is correct
9 Correct 7 ms 3840 KB Output is correct
10 Correct 7 ms 3840 KB Output is correct
11 Correct 7 ms 3840 KB Output is correct
12 Correct 2 ms 1408 KB Output is correct
13 Correct 4 ms 1920 KB Output is correct
14 Correct 5 ms 2688 KB Output is correct
15 Correct 7 ms 3840 KB Output is correct
16 Correct 7 ms 3840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 288 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 2 ms 768 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 1 ms 768 KB Output is correct
23 Correct 2 ms 896 KB Output is correct
24 Correct 2 ms 768 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
28 Correct 2 ms 896 KB Output is correct
29 Correct 2 ms 896 KB Output is correct
30 Correct 2 ms 896 KB Output is correct
31 Correct 2 ms 768 KB Output is correct
32 Correct 2 ms 896 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 2 ms 768 KB Output is correct
36 Correct 2 ms 768 KB Output is correct
37 Correct 1 ms 768 KB Output is correct
38 Correct 2 ms 768 KB Output is correct
39 Correct 2 ms 896 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 512 KB Output is correct
42 Correct 0 ms 256 KB Output is correct
43 Correct 7 ms 3840 KB Output is correct
44 Correct 7 ms 3840 KB Output is correct
45 Correct 7 ms 3840 KB Output is correct
46 Correct 7 ms 3840 KB Output is correct
47 Correct 7 ms 3840 KB Output is correct
48 Correct 7 ms 3840 KB Output is correct
49 Correct 9 ms 3840 KB Output is correct
50 Correct 7 ms 3840 KB Output is correct
51 Correct 7 ms 3840 KB Output is correct
52 Correct 7 ms 3840 KB Output is correct
53 Correct 2 ms 1408 KB Output is correct
54 Correct 4 ms 1920 KB Output is correct
55 Correct 5 ms 2688 KB Output is correct
56 Correct 7 ms 3840 KB Output is correct
57 Correct 7 ms 3840 KB Output is correct
58 Correct 334 ms 133240 KB Output is correct
59 Correct 339 ms 133244 KB Output is correct
60 Correct 343 ms 132344 KB Output is correct
61 Correct 347 ms 133880 KB Output is correct
62 Correct 27 ms 12416 KB Output is correct
63 Correct 49 ms 20736 KB Output is correct
64 Correct 167 ms 66680 KB Output is correct
65 Correct 240 ms 95608 KB Output is correct
66 Correct 325 ms 131916 KB Output is correct
67 Correct 344 ms 131936 KB Output is correct
68 Correct 374 ms 133920 KB Output is correct
69 Correct 345 ms 134904 KB Output is correct
70 Correct 374 ms 134340 KB Output is correct
71 Correct 332 ms 131064 KB Output is correct
72 Correct 90 ms 34296 KB Output is correct
73 Correct 22 ms 10624 KB Output is correct