# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
670321 | 2022-12-08T17:01:00 Z | dozer | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 67 ms | 174416 KB |
#include <bits/stdc++.h> using namespace std; #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define pb push_back #define pii pair<int, int> #define st first #define nd second #define endl "\n" #define sp " " #define N 405 int dp[N][N][N][4]; vector<int> r, g, y; int n; const int INF = 1e9 + 7; int f(int i, int j, int k, int last) { int t1 = INF, t2 = INF, t3 = INF; int pos = i + j + k + 1; if (pos > n) return 0; if (dp[i][j][k][last] != -1) return dp[i][j][k][last]; if (i < r.size() && last != 0) t1 = f(i + 1, j, k, 0) + abs(r[i] - pos); if (j < g.size() && last != 1) t2 = f(i, j + 1, k, 1) + abs(g[j] - pos); if (k < y.size() && last != 2) t3 = f(i, j, k + 1, 2) + abs(y[k] - pos); int res = min(t1, t2); res = min(res, t3); res = min(res, INF); return dp[i][j][k][last] = res; } int32_t main() { fastio(); cin>>n; for (int i = 1; i <= n; i++) { char tmp; cin>>tmp; if (tmp == 'R') r.pb(i); else if (tmp == 'Y') y.pb(i); else g.pb(i); } for (int i = 0; i <= r.size() + 5; i++) { for (int j = 0; j <= g.size() + 5; j++) { for (int k = 0; k <= y.size() + 5; k++) { for (int last = 0; last <= 3; last++) dp[i][j][k][last] = -1; } } } int ans = f(0, 0, 0, 3); if (ans >= INF) cout<<-1<<endl; else cout<<ans / 2<<endl; cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 468 KB | Output is correct |
2 | Correct | 0 ms | 468 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 596 KB | Output is correct |
5 | Correct | 1 ms | 724 KB | Output is correct |
6 | Correct | 1 ms | 852 KB | Output is correct |
7 | Correct | 1 ms | 852 KB | Output is correct |
8 | Correct | 0 ms | 852 KB | Output is correct |
9 | Correct | 1 ms | 980 KB | Output is correct |
10 | Correct | 1 ms | 980 KB | Output is correct |
11 | Incorrect | 1 ms | 852 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 468 KB | Output is correct |
2 | Correct | 0 ms | 468 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 596 KB | Output is correct |
5 | Correct | 1 ms | 724 KB | Output is correct |
6 | Correct | 1 ms | 852 KB | Output is correct |
7 | Correct | 1 ms | 852 KB | Output is correct |
8 | Correct | 0 ms | 852 KB | Output is correct |
9 | Correct | 1 ms | 980 KB | Output is correct |
10 | Correct | 1 ms | 980 KB | Output is correct |
11 | Incorrect | 1 ms | 852 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 468 KB | Output is correct |
2 | Correct | 66 ms | 174408 KB | Output is correct |
3 | Correct | 60 ms | 173548 KB | Output is correct |
4 | Correct | 61 ms | 174348 KB | Output is correct |
5 | Correct | 61 ms | 174380 KB | Output is correct |
6 | Correct | 67 ms | 174316 KB | Output is correct |
7 | Correct | 65 ms | 173572 KB | Output is correct |
8 | Correct | 65 ms | 173580 KB | Output is correct |
9 | Correct | 62 ms | 172748 KB | Output is correct |
10 | Correct | 61 ms | 174392 KB | Output is correct |
11 | Correct | 62 ms | 174416 KB | Output is correct |
12 | Correct | 20 ms | 49208 KB | Output is correct |
13 | Correct | 31 ms | 84436 KB | Output is correct |
14 | Correct | 44 ms | 120332 KB | Output is correct |
15 | Correct | 66 ms | 174404 KB | Output is correct |
16 | Correct | 60 ms | 174388 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 468 KB | Output is correct |
2 | Correct | 0 ms | 468 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 596 KB | Output is correct |
5 | Correct | 1 ms | 724 KB | Output is correct |
6 | Correct | 1 ms | 852 KB | Output is correct |
7 | Correct | 1 ms | 852 KB | Output is correct |
8 | Correct | 0 ms | 852 KB | Output is correct |
9 | Correct | 1 ms | 980 KB | Output is correct |
10 | Correct | 1 ms | 980 KB | Output is correct |
11 | Incorrect | 1 ms | 852 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |