# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
121582 | 2019-06-26T19:42:49 Z | zoooma13 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 5 ms | 3712 KB |
#include <bits/stdc++.h> using namespace std; #define MAX_N 65 int n; string s; vector <int> pos[3]; int dp[3][MAX_N][MAX_N][MAX_N] ,root = -1; int to_rch[3][MAX_N][MAX_N]; int solve(int t ,int p0=0 ,int p1=0 ,int p2=0){ int i = p0+p1+p2; if(i == n) return 0; int&ret = (~t ? dp[t][p0][p1][p2] : root); if(~ret) return ret; ret = 1e9; auto st = vector<int>{p0 ,p1 ,p2}; for(int nt=0; nt<3; nt++){ if(t == nt) continue; if(st[nt] < pos[nt].size()){ st[nt]++; ret = min(ret ,to_rch[nt][i][st[nt]-1]+solve(nt ,st[0] ,st[1] ,st[2])); st[nt]--; } } return ret; } int main() { cin >> n; cin >> s; for(int i=0; i<n; i++){ if(s[i] == 'R') pos[0].push_back(i); if(s[i] == 'G') pos[1].push_back(i); if(s[i] == 'Y') pos[2].push_back(i); } for(int t=0; t<3; t++){ for(int i=0; i<pos[t].size(); i++) for(int o=i; o<n; o++) to_rch[t][o][i] = max(pos[t][i]-o ,0); } memset(dp ,-1 ,sizeof dp); int ans = solve(-1); cout << (ans == 1e9 ? -1 : ans) << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3584 KB | Output is correct |
2 | Correct | 4 ms | 3584 KB | Output is correct |
3 | Correct | 5 ms | 3584 KB | Output is correct |
4 | Correct | 5 ms | 3584 KB | Output is correct |
5 | Correct | 5 ms | 3584 KB | Output is correct |
6 | Correct | 4 ms | 3584 KB | Output is correct |
7 | Correct | 4 ms | 3584 KB | Output is correct |
8 | Correct | 5 ms | 3584 KB | Output is correct |
9 | Correct | 4 ms | 3584 KB | Output is correct |
10 | Correct | 4 ms | 3584 KB | Output is correct |
11 | Incorrect | 4 ms | 3584 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3584 KB | Output is correct |
2 | Correct | 4 ms | 3584 KB | Output is correct |
3 | Correct | 5 ms | 3584 KB | Output is correct |
4 | Correct | 5 ms | 3584 KB | Output is correct |
5 | Correct | 5 ms | 3584 KB | Output is correct |
6 | Correct | 4 ms | 3584 KB | Output is correct |
7 | Correct | 4 ms | 3584 KB | Output is correct |
8 | Correct | 5 ms | 3584 KB | Output is correct |
9 | Correct | 4 ms | 3584 KB | Output is correct |
10 | Correct | 4 ms | 3584 KB | Output is correct |
11 | Incorrect | 4 ms | 3584 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3584 KB | Output is correct |
2 | Incorrect | 5 ms | 3712 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3584 KB | Output is correct |
2 | Correct | 4 ms | 3584 KB | Output is correct |
3 | Correct | 5 ms | 3584 KB | Output is correct |
4 | Correct | 5 ms | 3584 KB | Output is correct |
5 | Correct | 5 ms | 3584 KB | Output is correct |
6 | Correct | 4 ms | 3584 KB | Output is correct |
7 | Correct | 4 ms | 3584 KB | Output is correct |
8 | Correct | 5 ms | 3584 KB | Output is correct |
9 | Correct | 4 ms | 3584 KB | Output is correct |
10 | Correct | 4 ms | 3584 KB | Output is correct |
11 | Incorrect | 4 ms | 3584 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |