# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
99011 | 2019-02-28T05:28:42 Z | 조승현(#2855, ainta) | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 353 ms | 378776 KB |
#include<cstdio> #include<algorithm> #include<vector> using namespace std; int n, Num[200], C[3], V[410][3]; vector<int>U[3]; char p[410]; int D[410][410][410][3]; int main() { int i, j, k; Num['R'] = 0; Num['G'] = 1; Num['Y'] = 2; scanf("%d", &n); scanf("%s", p + 1); for (i = 1; i <= n; i++) { U[Num[p[i]]].push_back(i); V[i][0] = U[0].size(); V[i][1] = U[1].size(); V[i][2] = U[2].size(); } for (i = 0; i < 3; i++)C[i] = U[i].size(); for (i = 0; i <= n; i++) { for (j = 0; j <= i; j++) { for (k = 0; j+k <= i; k++) { D[i][j][k][0]=D[i][j][k][1]=D[i][j][k][2] = 1e9; } } } D[1][1][0][0] = (Num[p[1]] != 0); D[1][0][1][1] = (Num[p[1]] != 1); D[1][0][0][2] = (Num[p[1]] != 2); for (i = 1; i < n; i++) { for (j = 0; j <= i; j++) { for (k = 0; j+k <= i; k++) { int l = i - j - k; if (j > C[0] || k > C[1] || l > C[2])continue; for (int ii = 0; ii < 3; ii++) { int t = D[i][j][k][ii]; if (t > 1e8)continue; if (ii!=0 && j != C[0]) { int tp = U[0][j]; int s = max(V[tp][1] - k, 0) + max(V[tp][2] - l, 0); D[i + 1][j + 1][k][0] = min(D[i + 1][j + 1][k][0], t + s); } if (ii!=1 && k != C[1]) { int tp = U[1][k]; int s = max(V[tp][0] - j, 0) + max(V[tp][2] - l, 0); D[i + 1][j][k + 1][1] = min(D[i + 1][j][k + 1][1], t + s); } if (ii!=2 && l != C[2]) { int tp = U[2][l]; int s = max(V[tp][0] - j, 0) + max(V[tp][1] - k, 0); D[i + 1][j][k][2] = min(D[i + 1][j][k][2], t + s); } } } } } int res = 1e9; for (i = 0; i < 3; i++) { res = min(res, D[n][C[0]][C[1]][i]); } if (res > 1e8) { puts("-1"); } else { printf("%d\n", res); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 640 KB | Output is correct |
5 | Correct | 3 ms | 896 KB | Output is correct |
6 | Correct | 3 ms | 896 KB | Output is correct |
7 | Incorrect | 2 ms | 896 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 640 KB | Output is correct |
5 | Correct | 3 ms | 896 KB | Output is correct |
6 | Correct | 3 ms | 896 KB | Output is correct |
7 | Incorrect | 2 ms | 896 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 330 ms | 378628 KB | Output is correct |
3 | Correct | 328 ms | 376912 KB | Output is correct |
4 | Correct | 353 ms | 378776 KB | Output is correct |
5 | Correct | 338 ms | 378772 KB | Output is correct |
6 | Incorrect | 318 ms | 378732 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 640 KB | Output is correct |
5 | Correct | 3 ms | 896 KB | Output is correct |
6 | Correct | 3 ms | 896 KB | Output is correct |
7 | Incorrect | 2 ms | 896 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |