# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
120421 | 2019-06-24T12:41:59 Z | Just_Solve_The_Problem | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++11 | 31 ms | 760 KB |
#include <bits/stdc++.h> #define ll long long #define ok puts("OK"); using namespace std; const int inf = (int)1e9 + 7; const int N = (int)1500 + 7; int dp[2][N][1 << 3][3]; int n; string S; int s[N]; int asd[10]; main() { memset(dp, 63, sizeof dp); scanf("%d", &n); cin >> S; for (int i = 0; i < n; i++) { int x; if (S[i] == 'R') x = 0; if (S[i] == 'G') x = 1; if (S[i] == 'Y') x = 2; s[i + 1] = x; } for (int mask = 1; mask < 8; mask++) { for (int j = 0; j < 3; j++) { if ((mask >> j) & 1) { asd[mask] = j; } } } dp[1][1][1 << s[1]][s[1]] = 0; for (int i = 1; i < n; i++) { int nxt = (i & 1 ^ 1); memset(dp[nxt], 63, sizeof dp[nxt]); for (int j = 1; j <= n; j++) { for (int mask = 1; mask < 8; mask++) { for (int last = 0; last < 3; last++) { int res = dp[i & 1][j][mask][last]; dp[nxt][j + 1][mask | (1 << s[i + 1])][last] = min(dp[nxt][j + 1][mask | (1 << s[i + 1])][last], res); if ((mask >> s[i + 1]) & 1) continue; if (last != s[i + 1]) { dp[nxt][j][mask][s[i + 1]] = min(dp[nxt][j][mask][s[i + 1]], res + j); } if (j > 1) { dp[nxt][j - 1][mask][s[i + 1]] = min(dp[nxt][j - 1][mask][s[i + 1]], res + j - 1); } else { dp[nxt][j][1 << s[i + 1]][asd[mask]] = min(dp[nxt][j][1 << s[i + 1]][asd[mask]], res); } } } } } int ans = 1e9 + 2; for (int i = 1; i < 5; i++) for (int j = 0; j < 3; j++) ans = min(ans, dp[n & 1][1][i][j]); if (ans > 1e9) ans = -1; cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 640 KB | Output is correct |
2 | Correct | 2 ms | 640 KB | Output is correct |
3 | Correct | 2 ms | 640 KB | Output is correct |
4 | Correct | 2 ms | 640 KB | Output is correct |
5 | Correct | 2 ms | 640 KB | Output is correct |
6 | Correct | 2 ms | 640 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
8 | Correct | 3 ms | 640 KB | Output is correct |
9 | Correct | 2 ms | 640 KB | Output is correct |
10 | Correct | 2 ms | 688 KB | Output is correct |
11 | Correct | 2 ms | 640 KB | Output is correct |
12 | Correct | 2 ms | 640 KB | Output is correct |
13 | Correct | 2 ms | 640 KB | Output is correct |
14 | Correct | 2 ms | 640 KB | Output is correct |
15 | Correct | 2 ms | 640 KB | Output is correct |
16 | Correct | 2 ms | 640 KB | Output is correct |
17 | Correct | 2 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 640 KB | Output is correct |
2 | Correct | 2 ms | 640 KB | Output is correct |
3 | Correct | 2 ms | 640 KB | Output is correct |
4 | Correct | 2 ms | 640 KB | Output is correct |
5 | Correct | 2 ms | 640 KB | Output is correct |
6 | Correct | 2 ms | 640 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
8 | Correct | 3 ms | 640 KB | Output is correct |
9 | Correct | 2 ms | 640 KB | Output is correct |
10 | Correct | 2 ms | 688 KB | Output is correct |
11 | Correct | 2 ms | 640 KB | Output is correct |
12 | Correct | 2 ms | 640 KB | Output is correct |
13 | Correct | 2 ms | 640 KB | Output is correct |
14 | Correct | 2 ms | 640 KB | Output is correct |
15 | Correct | 2 ms | 640 KB | Output is correct |
16 | Correct | 2 ms | 640 KB | Output is correct |
17 | Correct | 2 ms | 640 KB | Output is correct |
18 | Correct | 2 ms | 640 KB | Output is correct |
19 | Correct | 2 ms | 640 KB | Output is correct |
20 | Correct | 3 ms | 640 KB | Output is correct |
21 | Correct | 2 ms | 640 KB | Output is correct |
22 | Correct | 2 ms | 640 KB | Output is correct |
23 | Correct | 3 ms | 640 KB | Output is correct |
24 | Correct | 3 ms | 640 KB | Output is correct |
25 | Correct | 3 ms | 640 KB | Output is correct |
26 | Correct | 3 ms | 640 KB | Output is correct |
27 | Correct | 3 ms | 640 KB | Output is correct |
28 | Correct | 3 ms | 640 KB | Output is correct |
29 | Correct | 3 ms | 640 KB | Output is correct |
30 | Correct | 3 ms | 640 KB | Output is correct |
31 | Correct | 3 ms | 640 KB | Output is correct |
32 | Correct | 2 ms | 640 KB | Output is correct |
33 | Correct | 3 ms | 640 KB | Output is correct |
34 | Correct | 3 ms | 640 KB | Output is correct |
35 | Correct | 3 ms | 640 KB | Output is correct |
36 | Correct | 3 ms | 640 KB | Output is correct |
37 | Correct | 3 ms | 640 KB | Output is correct |
38 | Correct | 3 ms | 640 KB | Output is correct |
39 | Correct | 3 ms | 640 KB | Output is correct |
40 | Correct | 3 ms | 640 KB | Output is correct |
41 | Correct | 3 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 640 KB | Output is correct |
2 | Correct | 13 ms | 640 KB | Output is correct |
3 | Correct | 14 ms | 640 KB | Output is correct |
4 | Correct | 21 ms | 640 KB | Output is correct |
5 | Correct | 13 ms | 640 KB | Output is correct |
6 | Correct | 13 ms | 640 KB | Output is correct |
7 | Correct | 13 ms | 640 KB | Output is correct |
8 | Correct | 13 ms | 640 KB | Output is correct |
9 | Correct | 12 ms | 760 KB | Output is correct |
10 | Correct | 13 ms | 640 KB | Output is correct |
11 | Correct | 13 ms | 640 KB | Output is correct |
12 | Correct | 6 ms | 640 KB | Output is correct |
13 | Correct | 8 ms | 640 KB | Output is correct |
14 | Correct | 10 ms | 652 KB | Output is correct |
15 | Correct | 12 ms | 640 KB | Output is correct |
16 | Correct | 13 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 640 KB | Output is correct |
2 | Correct | 2 ms | 640 KB | Output is correct |
3 | Correct | 2 ms | 640 KB | Output is correct |
4 | Correct | 2 ms | 640 KB | Output is correct |
5 | Correct | 2 ms | 640 KB | Output is correct |
6 | Correct | 2 ms | 640 KB | Output is correct |
7 | Correct | 2 ms | 640 KB | Output is correct |
8 | Correct | 3 ms | 640 KB | Output is correct |
9 | Correct | 2 ms | 640 KB | Output is correct |
10 | Correct | 2 ms | 688 KB | Output is correct |
11 | Correct | 2 ms | 640 KB | Output is correct |
12 | Correct | 2 ms | 640 KB | Output is correct |
13 | Correct | 2 ms | 640 KB | Output is correct |
14 | Correct | 2 ms | 640 KB | Output is correct |
15 | Correct | 2 ms | 640 KB | Output is correct |
16 | Correct | 2 ms | 640 KB | Output is correct |
17 | Correct | 2 ms | 640 KB | Output is correct |
18 | Correct | 2 ms | 640 KB | Output is correct |
19 | Correct | 2 ms | 640 KB | Output is correct |
20 | Correct | 3 ms | 640 KB | Output is correct |
21 | Correct | 2 ms | 640 KB | Output is correct |
22 | Correct | 2 ms | 640 KB | Output is correct |
23 | Correct | 3 ms | 640 KB | Output is correct |
24 | Correct | 3 ms | 640 KB | Output is correct |
25 | Correct | 3 ms | 640 KB | Output is correct |
26 | Correct | 3 ms | 640 KB | Output is correct |
27 | Correct | 3 ms | 640 KB | Output is correct |
28 | Correct | 3 ms | 640 KB | Output is correct |
29 | Correct | 3 ms | 640 KB | Output is correct |
30 | Correct | 3 ms | 640 KB | Output is correct |
31 | Correct | 3 ms | 640 KB | Output is correct |
32 | Correct | 2 ms | 640 KB | Output is correct |
33 | Correct | 3 ms | 640 KB | Output is correct |
34 | Correct | 3 ms | 640 KB | Output is correct |
35 | Correct | 3 ms | 640 KB | Output is correct |
36 | Correct | 3 ms | 640 KB | Output is correct |
37 | Correct | 3 ms | 640 KB | Output is correct |
38 | Correct | 3 ms | 640 KB | Output is correct |
39 | Correct | 3 ms | 640 KB | Output is correct |
40 | Correct | 3 ms | 640 KB | Output is correct |
41 | Correct | 3 ms | 640 KB | Output is correct |
42 | Correct | 2 ms | 640 KB | Output is correct |
43 | Correct | 13 ms | 640 KB | Output is correct |
44 | Correct | 14 ms | 640 KB | Output is correct |
45 | Correct | 21 ms | 640 KB | Output is correct |
46 | Correct | 13 ms | 640 KB | Output is correct |
47 | Correct | 13 ms | 640 KB | Output is correct |
48 | Correct | 13 ms | 640 KB | Output is correct |
49 | Correct | 13 ms | 640 KB | Output is correct |
50 | Correct | 12 ms | 760 KB | Output is correct |
51 | Correct | 13 ms | 640 KB | Output is correct |
52 | Correct | 13 ms | 640 KB | Output is correct |
53 | Correct | 6 ms | 640 KB | Output is correct |
54 | Correct | 8 ms | 640 KB | Output is correct |
55 | Correct | 10 ms | 652 KB | Output is correct |
56 | Correct | 12 ms | 640 KB | Output is correct |
57 | Correct | 13 ms | 640 KB | Output is correct |
58 | Correct | 14 ms | 640 KB | Output is correct |
59 | Correct | 13 ms | 640 KB | Output is correct |
60 | Correct | 13 ms | 640 KB | Output is correct |
61 | Correct | 13 ms | 640 KB | Output is correct |
62 | Correct | 13 ms | 640 KB | Output is correct |
63 | Correct | 13 ms | 612 KB | Output is correct |
64 | Correct | 13 ms | 640 KB | Output is correct |
65 | Correct | 13 ms | 640 KB | Output is correct |
66 | Correct | 24 ms | 640 KB | Output is correct |
67 | Correct | 31 ms | 640 KB | Output is correct |
68 | Correct | 13 ms | 640 KB | Output is correct |
69 | Correct | 14 ms | 640 KB | Output is correct |
70 | Correct | 12 ms | 640 KB | Output is correct |
71 | Correct | 13 ms | 640 KB | Output is correct |
72 | Correct | 13 ms | 640 KB | Output is correct |
73 | Correct | 12 ms | 640 KB | Output is correct |