답안 #272958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
272958 2020-08-19T00:03:44 Z ChrisT Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
75 / 100
500 ms 133368 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); 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);
	}
	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 = upper_bound(pos[j].begin(),pos[j].end(),idx) - pos[j].begin() + 1;
						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);
      |            ~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 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 1 ms 384 KB Output is correct
8 Correct 0 ms 384 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 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 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 1 ms 384 KB Output is correct
8 Correct 0 ms 384 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 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 3 ms 896 KB Output is correct
19 Correct 3 ms 896 KB Output is correct
20 Correct 2 ms 896 KB Output is correct
21 Correct 4 ms 896 KB Output is correct
22 Correct 2 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 512 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 3 ms 896 KB Output is correct
32 Correct 2 ms 1024 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 3 ms 768 KB Output is correct
36 Correct 2 ms 768 KB Output is correct
37 Correct 2 ms 768 KB Output is correct
38 Correct 2 ms 768 KB Output is correct
39 Correct 3 ms 896 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 8 ms 3840 KB Output is correct
3 Correct 8 ms 3840 KB Output is correct
4 Correct 9 ms 3840 KB Output is correct
5 Correct 9 ms 3840 KB Output is correct
6 Correct 9 ms 3840 KB Output is correct
7 Correct 9 ms 3840 KB Output is correct
8 Correct 9 ms 3840 KB Output is correct
9 Correct 9 ms 3840 KB Output is correct
10 Correct 9 ms 3840 KB Output is correct
11 Correct 8 ms 3840 KB Output is correct
12 Correct 3 ms 1280 KB Output is correct
13 Correct 4 ms 2048 KB Output is correct
14 Correct 6 ms 2688 KB Output is correct
15 Correct 9 ms 3872 KB Output is correct
16 Correct 9 ms 3840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 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 1 ms 384 KB Output is correct
8 Correct 0 ms 384 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 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 3 ms 896 KB Output is correct
19 Correct 3 ms 896 KB Output is correct
20 Correct 2 ms 896 KB Output is correct
21 Correct 4 ms 896 KB Output is correct
22 Correct 2 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 512 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 3 ms 896 KB Output is correct
32 Correct 2 ms 1024 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 3 ms 768 KB Output is correct
36 Correct 2 ms 768 KB Output is correct
37 Correct 2 ms 768 KB Output is correct
38 Correct 2 ms 768 KB Output is correct
39 Correct 3 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 8 ms 3840 KB Output is correct
44 Correct 8 ms 3840 KB Output is correct
45 Correct 9 ms 3840 KB Output is correct
46 Correct 9 ms 3840 KB Output is correct
47 Correct 9 ms 3840 KB Output is correct
48 Correct 9 ms 3840 KB Output is correct
49 Correct 9 ms 3840 KB Output is correct
50 Correct 9 ms 3840 KB Output is correct
51 Correct 9 ms 3840 KB Output is correct
52 Correct 8 ms 3840 KB Output is correct
53 Correct 3 ms 1280 KB Output is correct
54 Correct 4 ms 2048 KB Output is correct
55 Correct 6 ms 2688 KB Output is correct
56 Correct 9 ms 3872 KB Output is correct
57 Correct 9 ms 3840 KB Output is correct
58 Execution timed out 531 ms 133368 KB Time limit exceeded
59 Halted 0 ms 0 KB -