# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
367357 | 2021-02-16T23:40:42 Z | lookcook | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 500 ms | 975112 KB |
#include <bits/stdc++.h> #define int long long using namespace std; int dp[3][70][70][70][70]; // 0 = r, 1 = g, 2 = y int n; vector<int> r, g, y; int rec(int pos, int rp, int gp, int yp, int lst) { if (pos == n) return 0; if (dp[lst][pos][rp][gp][yp] != -1) return dp[lst][pos][rp][gp][yp]; int res = 1e15; if (r.size()!=rp && lst!=0) res = min(res, rec(pos+1, rp+1, gp, yp, 0) + abs(r[rp]-pos)); if (g.size()!=gp && lst!=1) res = min(res, rec(pos+1, rp, gp+1, yp, 1) + abs(g[gp]-pos)); if (y.size()!=yp && lst!=2) res = min(res, rec(pos+1, rp, gp, yp+1, 2) + abs(y[yp]-pos)); dp[lst][pos][rp][gp][yp] = res; return res; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); for (int i = 0; i < 3; i++) for (int a = 0; a < 70; a++) for (int b = 0; b < 70; b++) for (int c = 0; c < 70; c++) for (int d = 0; d < 70; d++) dp[i][a][b][c][d] = -1; string s; cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == 'R') r.push_back(i); if (s[i] == 'G') g.push_back(i); if (s[i] == 'Y') y.push_back(i); } int res = min(rec(0,0,0,0,1),rec(0,0,0,0,0)); if (res >= 1e15) cout << "-1\n"; else cout << res/2 << '\n'; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 339 ms | 564332 KB | Output is correct |
2 | Correct | 323 ms | 564204 KB | Output is correct |
3 | Correct | 327 ms | 564280 KB | Output is correct |
4 | Correct | 347 ms | 564204 KB | Output is correct |
5 | Correct | 324 ms | 564204 KB | Output is correct |
6 | Correct | 337 ms | 564204 KB | Output is correct |
7 | Correct | 330 ms | 564204 KB | Output is correct |
8 | Correct | 324 ms | 564204 KB | Output is correct |
9 | Correct | 322 ms | 564204 KB | Output is correct |
10 | Correct | 333 ms | 564332 KB | Output is correct |
11 | Incorrect | 328 ms | 564204 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 339 ms | 564332 KB | Output is correct |
2 | Correct | 323 ms | 564204 KB | Output is correct |
3 | Correct | 327 ms | 564280 KB | Output is correct |
4 | Correct | 347 ms | 564204 KB | Output is correct |
5 | Correct | 324 ms | 564204 KB | Output is correct |
6 | Correct | 337 ms | 564204 KB | Output is correct |
7 | Correct | 330 ms | 564204 KB | Output is correct |
8 | Correct | 324 ms | 564204 KB | Output is correct |
9 | Correct | 322 ms | 564204 KB | Output is correct |
10 | Correct | 333 ms | 564332 KB | Output is correct |
11 | Incorrect | 328 ms | 564204 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 328 ms | 564204 KB | Output is correct |
2 | Execution timed out | 1102 ms | 975112 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 339 ms | 564332 KB | Output is correct |
2 | Correct | 323 ms | 564204 KB | Output is correct |
3 | Correct | 327 ms | 564280 KB | Output is correct |
4 | Correct | 347 ms | 564204 KB | Output is correct |
5 | Correct | 324 ms | 564204 KB | Output is correct |
6 | Correct | 337 ms | 564204 KB | Output is correct |
7 | Correct | 330 ms | 564204 KB | Output is correct |
8 | Correct | 324 ms | 564204 KB | Output is correct |
9 | Correct | 322 ms | 564204 KB | Output is correct |
10 | Correct | 333 ms | 564332 KB | Output is correct |
11 | Incorrect | 328 ms | 564204 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |