# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
474177 | 2021-09-17T07:49:42 Z | ntabc05101 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 172 ms | 28744 KB |
#include<bits/stdc++.h> using namespace std; #define taskname "" const int inf = 1e9 + 9; const string bs = "RGY"; int main() { if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } cin.tie(0)->sync_with_stdio(0); int n; cin >> n; string s; cin >> s; vector<int> pos[3]; int prf[3][n + 1]; for (int t = 0; t < 3; t++) { prf[t][0] = 0; pos[t].push_back(0); for (int i = 0; i < n; i++) { prf[t][i + 1] = prf[t][i]; if (s[i] == bs[t]) { pos[t].push_back(i + 1); prf[t][i + 1]++; } } } int dp[3][prf[0][n] + 1][prf[1][n] + 1][prf[2][n] + 1]; for (int t = 0; t < 3; t++) { for (int i = 0; i <= prf[0][n]; i++) { for (int j = 0; j <= prf[1][n]; j++) { for (int k = 0; k <= prf[2][n]; k++) { dp[t][i][j][k] = inf; } } } dp[t][0][0][0] = 0; } //cout << prf[0][n] << " " << prf[1][n] << " " << prf[2][n] << "\n"; /*for (int t = 0; t < 3; t++) { cout << dp[t][prf[0][n]][prf[1][n]][prf[2][n]] << "\n"; }*/ int z[3]; for (z[0] = 0; z[0] <= prf[0][n]; z[0]++) { for (z[1] = 0; z[1] <= prf[1][n]; z[1]++) { for (z[2] = 0; z[2] <= prf[2][n]; z[2]++) { for (int prv = 0; prv < 3; prv++) { for (int cur = 0; cur < 3; cur++) { if (cur == prv || z[cur] == prf[cur][n]) { continue; } int res = dp[prv][z[0]][z[1]][z[2]]; int dff = ((cur + 1) ^ (prv + 1)) - 1; int p1 = pos[cur][z[cur] + 1], p2 = pos[prv][z[prv]], p3 = pos[dff][z[dff]]; res += max(0, prf[prv][p1] - prf[prv][p2]) + max(0, prf[dff][p1] - prf[dff][p3]); p1 = z[0] + (cur == 0); p2 = z[1] + (cur == 1); p3 = z[2] + (cur == 2); dp[cur][p1][p2][p3] = min(dp[cur][p1][p2][p3], res); } } } } } int res = inf; for (int t = 0; t < 3; t++) { //cout << res << "\n"; res = min(res, dp[t][prf[0][n]][prf[1][n]][prf[2][n]]); } cout << (res == inf ? -1: res) << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 316 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 312 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 312 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 1 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 316 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 312 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 312 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 1 ms | 204 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 312 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 332 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 332 KB | Output is correct |
28 | Correct | 1 ms | 312 KB | Output is correct |
29 | Correct | 1 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 332 KB | Output is correct |
31 | Correct | 1 ms | 312 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 1 ms | 332 KB | Output is correct |
34 | Correct | 1 ms | 332 KB | Output is correct |
35 | Correct | 2 ms | 332 KB | Output is correct |
36 | Correct | 1 ms | 332 KB | Output is correct |
37 | Correct | 1 ms | 312 KB | Output is correct |
38 | Correct | 1 ms | 332 KB | Output is correct |
39 | Correct | 1 ms | 332 KB | Output is correct |
40 | Correct | 1 ms | 308 KB | Output is correct |
41 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 312 KB | Output is correct |
2 | Correct | 3 ms | 716 KB | Output is correct |
3 | Correct | 3 ms | 696 KB | Output is correct |
4 | Correct | 3 ms | 716 KB | Output is correct |
5 | Correct | 3 ms | 716 KB | Output is correct |
6 | Correct | 3 ms | 716 KB | Output is correct |
7 | Correct | 3 ms | 716 KB | Output is correct |
8 | Correct | 3 ms | 696 KB | Output is correct |
9 | Correct | 3 ms | 716 KB | Output is correct |
10 | Correct | 3 ms | 716 KB | Output is correct |
11 | Correct | 3 ms | 716 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 2 ms | 460 KB | Output is correct |
14 | Correct | 2 ms | 588 KB | Output is correct |
15 | Correct | 3 ms | 716 KB | Output is correct |
16 | Correct | 3 ms | 716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 316 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 312 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 312 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 1 ms | 204 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 312 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 332 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 332 KB | Output is correct |
28 | Correct | 1 ms | 312 KB | Output is correct |
29 | Correct | 1 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 332 KB | Output is correct |
31 | Correct | 1 ms | 312 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 1 ms | 332 KB | Output is correct |
34 | Correct | 1 ms | 332 KB | Output is correct |
35 | Correct | 2 ms | 332 KB | Output is correct |
36 | Correct | 1 ms | 332 KB | Output is correct |
37 | Correct | 1 ms | 312 KB | Output is correct |
38 | Correct | 1 ms | 332 KB | Output is correct |
39 | Correct | 1 ms | 332 KB | Output is correct |
40 | Correct | 1 ms | 308 KB | Output is correct |
41 | Correct | 1 ms | 332 KB | Output is correct |
42 | Correct | 0 ms | 312 KB | Output is correct |
43 | Correct | 3 ms | 716 KB | Output is correct |
44 | Correct | 3 ms | 696 KB | Output is correct |
45 | Correct | 3 ms | 716 KB | Output is correct |
46 | Correct | 3 ms | 716 KB | Output is correct |
47 | Correct | 3 ms | 716 KB | Output is correct |
48 | Correct | 3 ms | 716 KB | Output is correct |
49 | Correct | 3 ms | 696 KB | Output is correct |
50 | Correct | 3 ms | 716 KB | Output is correct |
51 | Correct | 3 ms | 716 KB | Output is correct |
52 | Correct | 3 ms | 716 KB | Output is correct |
53 | Correct | 1 ms | 332 KB | Output is correct |
54 | Correct | 2 ms | 460 KB | Output is correct |
55 | Correct | 2 ms | 588 KB | Output is correct |
56 | Correct | 3 ms | 716 KB | Output is correct |
57 | Correct | 3 ms | 716 KB | Output is correct |
58 | Correct | 169 ms | 28436 KB | Output is correct |
59 | Correct | 170 ms | 28456 KB | Output is correct |
60 | Correct | 168 ms | 28252 KB | Output is correct |
61 | Correct | 172 ms | 28616 KB | Output is correct |
62 | Correct | 15 ms | 2620 KB | Output is correct |
63 | Correct | 25 ms | 4408 KB | Output is correct |
64 | Correct | 81 ms | 14204 KB | Output is correct |
65 | Correct | 117 ms | 20300 KB | Output is correct |
66 | Correct | 162 ms | 28136 KB | Output is correct |
67 | Correct | 162 ms | 28108 KB | Output is correct |
68 | Correct | 168 ms | 28492 KB | Output is correct |
69 | Correct | 167 ms | 28744 KB | Output is correct |
70 | Correct | 168 ms | 28684 KB | Output is correct |
71 | Correct | 161 ms | 28008 KB | Output is correct |
72 | Correct | 43 ms | 7372 KB | Output is correct |
73 | Correct | 11 ms | 2124 KB | Output is correct |