Submission #118867

# Submission time Handle Problem Language Result Execution time Memory
118867 2019-06-20T00:11:43 Z tmwilliamlin168 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
29 ms 20580 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN=400;
int n, dp[mxN][8][mxN+1][4], b[mxN][7];
string s;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> s;
	for(char &c : s)
		c=(c>'G')+(c>'R');
	for(int i=0; i<n; ++i) {
		if(i)
			memcpy(b[i], b[i-1], sizeof(b[0]));
		for(int j=1; j<7; ++j)
			if(j>>s[i]&1)
				b[i][j]=s[i];
	}
	memset(dp, 0x3f, sizeof(dp));
	dp[0][1<<s[0]][1][3]=0;
	auto tm=[](int &a, int b) {
		a=min(a, b);
	};
	for(int i=1; i<n; ++i) {
		for(int j=1; j<7; ++j) {
			for(int k=1; k<=i; ++k) {
				for(int l=0; l<4; ++l) {
					tm(dp[i][j|1<<s[i]][k+1][l], dp[i-1][j][k][l]);
					if(j>>s[i]&1)
						continue;
					if(l!=s[i])
						tm(dp[i][j][k][s[i]], dp[i-1][j][k][l]+k);
					if(k>1)
						tm(dp[i][j][k-1][s[i]], dp[i-1][j][k][l]+k-1);
					else
						tm(dp[i][1<<s[i]][1][b[i-1][j]], dp[i-1][j][1][l]);
				}
			}
		}
	}
	int ans=1e9;
	for(int i=1; i<5; ++i)
		for(int j=0; j<4; ++j)
			ans=min(dp[n-1][i][1][j], ans);
	cout << (ans>=1e9?-1:ans);
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:35:26: warning: array subscript has type 'char' [-Wchar-subscripts]
       tm(dp[i][j][k][s[i]], dp[i-1][j][k][l]+k);
                          ^
joi2019_ho_t3.cpp:37:28: warning: array subscript has type 'char' [-Wchar-subscripts]
       tm(dp[i][j][k-1][s[i]], dp[i-1][j][k][l]+k-1);
                            ^
# Verdict Execution time Memory Grader output
1 Correct 17 ms 20480 KB Output is correct
2 Correct 16 ms 20472 KB Output is correct
3 Correct 17 ms 20480 KB Output is correct
4 Correct 17 ms 20352 KB Output is correct
5 Correct 17 ms 20480 KB Output is correct
6 Correct 16 ms 20344 KB Output is correct
7 Correct 19 ms 20480 KB Output is correct
8 Correct 16 ms 20480 KB Output is correct
9 Correct 16 ms 20480 KB Output is correct
10 Correct 16 ms 20480 KB Output is correct
11 Correct 17 ms 20480 KB Output is correct
12 Correct 17 ms 20352 KB Output is correct
13 Correct 16 ms 20480 KB Output is correct
14 Correct 17 ms 20480 KB Output is correct
15 Correct 17 ms 20352 KB Output is correct
16 Correct 18 ms 20480 KB Output is correct
17 Correct 16 ms 20396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 20480 KB Output is correct
2 Correct 16 ms 20472 KB Output is correct
3 Correct 17 ms 20480 KB Output is correct
4 Correct 17 ms 20352 KB Output is correct
5 Correct 17 ms 20480 KB Output is correct
6 Correct 16 ms 20344 KB Output is correct
7 Correct 19 ms 20480 KB Output is correct
8 Correct 16 ms 20480 KB Output is correct
9 Correct 16 ms 20480 KB Output is correct
10 Correct 16 ms 20480 KB Output is correct
11 Correct 17 ms 20480 KB Output is correct
12 Correct 17 ms 20352 KB Output is correct
13 Correct 16 ms 20480 KB Output is correct
14 Correct 17 ms 20480 KB Output is correct
15 Correct 17 ms 20352 KB Output is correct
16 Correct 18 ms 20480 KB Output is correct
17 Correct 16 ms 20396 KB Output is correct
18 Correct 17 ms 20480 KB Output is correct
19 Correct 17 ms 20480 KB Output is correct
20 Correct 17 ms 20480 KB Output is correct
21 Correct 18 ms 20480 KB Output is correct
22 Correct 18 ms 20480 KB Output is correct
23 Correct 17 ms 20480 KB Output is correct
24 Correct 17 ms 20480 KB Output is correct
25 Correct 17 ms 20480 KB Output is correct
26 Correct 17 ms 20480 KB Output is correct
27 Correct 17 ms 20480 KB Output is correct
28 Correct 17 ms 20480 KB Output is correct
29 Correct 16 ms 20480 KB Output is correct
30 Correct 16 ms 20480 KB Output is correct
31 Correct 17 ms 20480 KB Output is correct
32 Correct 17 ms 20480 KB Output is correct
33 Correct 17 ms 20480 KB Output is correct
34 Correct 17 ms 20480 KB Output is correct
35 Correct 17 ms 20480 KB Output is correct
36 Correct 17 ms 20480 KB Output is correct
37 Correct 17 ms 20480 KB Output is correct
38 Correct 21 ms 20480 KB Output is correct
39 Correct 17 ms 20480 KB Output is correct
40 Correct 17 ms 20480 KB Output is correct
41 Correct 17 ms 20480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 20480 KB Output is correct
2 Correct 26 ms 20516 KB Output is correct
3 Correct 26 ms 20472 KB Output is correct
4 Correct 26 ms 20480 KB Output is correct
5 Correct 24 ms 20408 KB Output is correct
6 Correct 24 ms 20480 KB Output is correct
7 Correct 26 ms 20480 KB Output is correct
8 Correct 25 ms 20480 KB Output is correct
9 Correct 25 ms 20472 KB Output is correct
10 Correct 25 ms 20480 KB Output is correct
11 Correct 26 ms 20480 KB Output is correct
12 Correct 19 ms 20480 KB Output is correct
13 Correct 21 ms 20480 KB Output is correct
14 Correct 23 ms 20480 KB Output is correct
15 Correct 25 ms 20480 KB Output is correct
16 Correct 25 ms 20480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 20480 KB Output is correct
2 Correct 16 ms 20472 KB Output is correct
3 Correct 17 ms 20480 KB Output is correct
4 Correct 17 ms 20352 KB Output is correct
5 Correct 17 ms 20480 KB Output is correct
6 Correct 16 ms 20344 KB Output is correct
7 Correct 19 ms 20480 KB Output is correct
8 Correct 16 ms 20480 KB Output is correct
9 Correct 16 ms 20480 KB Output is correct
10 Correct 16 ms 20480 KB Output is correct
11 Correct 17 ms 20480 KB Output is correct
12 Correct 17 ms 20352 KB Output is correct
13 Correct 16 ms 20480 KB Output is correct
14 Correct 17 ms 20480 KB Output is correct
15 Correct 17 ms 20352 KB Output is correct
16 Correct 18 ms 20480 KB Output is correct
17 Correct 16 ms 20396 KB Output is correct
18 Correct 17 ms 20480 KB Output is correct
19 Correct 17 ms 20480 KB Output is correct
20 Correct 17 ms 20480 KB Output is correct
21 Correct 18 ms 20480 KB Output is correct
22 Correct 18 ms 20480 KB Output is correct
23 Correct 17 ms 20480 KB Output is correct
24 Correct 17 ms 20480 KB Output is correct
25 Correct 17 ms 20480 KB Output is correct
26 Correct 17 ms 20480 KB Output is correct
27 Correct 17 ms 20480 KB Output is correct
28 Correct 17 ms 20480 KB Output is correct
29 Correct 16 ms 20480 KB Output is correct
30 Correct 16 ms 20480 KB Output is correct
31 Correct 17 ms 20480 KB Output is correct
32 Correct 17 ms 20480 KB Output is correct
33 Correct 17 ms 20480 KB Output is correct
34 Correct 17 ms 20480 KB Output is correct
35 Correct 17 ms 20480 KB Output is correct
36 Correct 17 ms 20480 KB Output is correct
37 Correct 17 ms 20480 KB Output is correct
38 Correct 21 ms 20480 KB Output is correct
39 Correct 17 ms 20480 KB Output is correct
40 Correct 17 ms 20480 KB Output is correct
41 Correct 17 ms 20480 KB Output is correct
42 Correct 17 ms 20480 KB Output is correct
43 Correct 26 ms 20516 KB Output is correct
44 Correct 26 ms 20472 KB Output is correct
45 Correct 26 ms 20480 KB Output is correct
46 Correct 24 ms 20408 KB Output is correct
47 Correct 24 ms 20480 KB Output is correct
48 Correct 26 ms 20480 KB Output is correct
49 Correct 25 ms 20480 KB Output is correct
50 Correct 25 ms 20472 KB Output is correct
51 Correct 25 ms 20480 KB Output is correct
52 Correct 26 ms 20480 KB Output is correct
53 Correct 19 ms 20480 KB Output is correct
54 Correct 21 ms 20480 KB Output is correct
55 Correct 23 ms 20480 KB Output is correct
56 Correct 25 ms 20480 KB Output is correct
57 Correct 25 ms 20480 KB Output is correct
58 Correct 24 ms 20480 KB Output is correct
59 Correct 24 ms 20480 KB Output is correct
60 Correct 25 ms 20480 KB Output is correct
61 Correct 25 ms 20472 KB Output is correct
62 Correct 24 ms 20580 KB Output is correct
63 Correct 26 ms 20480 KB Output is correct
64 Correct 25 ms 20472 KB Output is correct
65 Correct 25 ms 20480 KB Output is correct
66 Correct 25 ms 20476 KB Output is correct
67 Correct 25 ms 20480 KB Output is correct
68 Correct 25 ms 20480 KB Output is correct
69 Correct 25 ms 20480 KB Output is correct
70 Correct 25 ms 20480 KB Output is correct
71 Correct 26 ms 20480 KB Output is correct
72 Correct 29 ms 20516 KB Output is correct
73 Correct 27 ms 20480 KB Output is correct