# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
526915 | 2022-02-16T16:20:38 Z | AdamGS | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 38 ms | 28652 KB |
#include<bits/stdc++.h> using namespace std; #define rep(a, b) for(int a = 0; a < (b); ++a) #define pb push_back const int LIM=407, INF=1e9+7; vector<int>V[3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; string s; cin >> n >> s; int ile[n][3]; rep(i, n) { rep(j, 3) ile[i][j]=0; if(i) rep(j, 3) ile[i][j]=ile[i-1][j]; if(s[i]=='R') { V[0].pb(i); ++ile[i][0]; } else if(s[i]=='G') { V[1].pb(i); ++ile[i][1]; } else { V[2].pb(i); ++ile[i][2]; } } int dp[V[0].size()+1][V[1].size()+1][V[2].size()+1][3]; rep(a, V[0].size()+1) rep(b, V[1].size()+1) rep(c, V[2].size()+1) rep(i, 3) dp[a][b][c][i]=INF; rep(i, 3) dp[0][0][0][i]=0; rep(a, V[0].size()+1) rep(b, V[1].size()+1) rep(c, V[2].size()+1) { if(a) { int koszt=max(ile[V[0][a-1]][1]-b, 0)+max(ile[V[0][a-1]][2]-c, 0); dp[a][b][c][0]=min(dp[a][b][c][0], dp[a-1][b][c][1]+koszt); dp[a][b][c][0]=min(dp[a][b][c][0], dp[a-1][b][c][2]+koszt); } if(b) { int koszt=max(ile[V[1][b-1]][0]-a, 0)+max(ile[V[1][b-1]][2]-c, 0); dp[a][b][c][1]=min(dp[a][b][c][1], dp[a][b-1][c][0]+koszt); dp[a][b][c][1]=min(dp[a][b][c][1], dp[a][b-1][c][2]+koszt); } if(c) { int koszt=max(ile[V[2][c-1]][0]-a, 0)+max(ile[V[2][c-1]][1]-b, 0); dp[a][b][c][2]=min(dp[a][b][c][2], dp[a][b][c-1][0]+koszt); dp[a][b][c][2]=min(dp[a][b][c][2], dp[a][b][c-1][1]+koszt); } } int ans=INF; rep(i, 3) ans=min(ans, dp[V[0].size()][V[1].size()][V[2].size()][i]); cout << (ans==INF?-1:ans) << '\n'; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 312 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 308 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 1 ms | 312 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 0 ms | 204 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 312 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 308 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 1 ms | 312 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 0 ms | 204 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 312 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 0 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 304 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 304 KB | Output is correct |
26 | Correct | 0 ms | 204 KB | Output is correct |
27 | Correct | 1 ms | 312 KB | Output is correct |
28 | Correct | 1 ms | 332 KB | Output is correct |
29 | Correct | 1 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 332 KB | Output is correct |
31 | Correct | 1 ms | 312 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 1 ms | 332 KB | Output is correct |
34 | Correct | 1 ms | 332 KB | Output is correct |
35 | Correct | 1 ms | 308 KB | Output is correct |
36 | Correct | 0 ms | 332 KB | Output is correct |
37 | Correct | 1 ms | 332 KB | Output is correct |
38 | Correct | 1 ms | 332 KB | Output is correct |
39 | Correct | 1 ms | 308 KB | Output is correct |
40 | Correct | 1 ms | 204 KB | Output is correct |
41 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 716 KB | Output is correct |
3 | Correct | 1 ms | 716 KB | Output is correct |
4 | Correct | 1 ms | 716 KB | Output is correct |
5 | Correct | 1 ms | 696 KB | Output is correct |
6 | Correct | 1 ms | 716 KB | Output is correct |
7 | Correct | 1 ms | 716 KB | Output is correct |
8 | Correct | 1 ms | 716 KB | Output is correct |
9 | Correct | 1 ms | 716 KB | Output is correct |
10 | Correct | 1 ms | 716 KB | Output is correct |
11 | Correct | 1 ms | 716 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 432 KB | Output is correct |
14 | Correct | 1 ms | 588 KB | Output is correct |
15 | Correct | 1 ms | 716 KB | Output is correct |
16 | Correct | 1 ms | 716 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 312 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 308 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 1 ms | 312 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 0 ms | 204 KB | Output is correct |
17 | Correct | 0 ms | 204 KB | Output is correct |
18 | Correct | 1 ms | 332 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 312 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 0 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 304 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 1 ms | 304 KB | Output is correct |
26 | Correct | 0 ms | 204 KB | Output is correct |
27 | Correct | 1 ms | 312 KB | Output is correct |
28 | Correct | 1 ms | 332 KB | Output is correct |
29 | Correct | 1 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 332 KB | Output is correct |
31 | Correct | 1 ms | 312 KB | Output is correct |
32 | Correct | 1 ms | 332 KB | Output is correct |
33 | Correct | 1 ms | 332 KB | Output is correct |
34 | Correct | 1 ms | 332 KB | Output is correct |
35 | Correct | 1 ms | 308 KB | Output is correct |
36 | Correct | 0 ms | 332 KB | Output is correct |
37 | Correct | 1 ms | 332 KB | Output is correct |
38 | Correct | 1 ms | 332 KB | Output is correct |
39 | Correct | 1 ms | 308 KB | Output is correct |
40 | Correct | 1 ms | 204 KB | Output is correct |
41 | Correct | 1 ms | 332 KB | Output is correct |
42 | Correct | 1 ms | 204 KB | Output is correct |
43 | Correct | 1 ms | 716 KB | Output is correct |
44 | Correct | 1 ms | 716 KB | Output is correct |
45 | Correct | 1 ms | 716 KB | Output is correct |
46 | Correct | 1 ms | 696 KB | Output is correct |
47 | Correct | 1 ms | 716 KB | Output is correct |
48 | Correct | 1 ms | 716 KB | Output is correct |
49 | Correct | 1 ms | 716 KB | Output is correct |
50 | Correct | 1 ms | 716 KB | Output is correct |
51 | Correct | 1 ms | 716 KB | Output is correct |
52 | Correct | 1 ms | 716 KB | Output is correct |
53 | Correct | 1 ms | 332 KB | Output is correct |
54 | Correct | 1 ms | 432 KB | Output is correct |
55 | Correct | 1 ms | 588 KB | Output is correct |
56 | Correct | 1 ms | 716 KB | Output is correct |
57 | Correct | 1 ms | 716 KB | Output is correct |
58 | Correct | 36 ms | 28444 KB | Output is correct |
59 | Correct | 34 ms | 28460 KB | Output is correct |
60 | Correct | 34 ms | 28236 KB | Output is correct |
61 | Correct | 34 ms | 28492 KB | Output is correct |
62 | Correct | 3 ms | 2508 KB | Output is correct |
63 | Correct | 5 ms | 4300 KB | Output is correct |
64 | Correct | 19 ms | 14140 KB | Output is correct |
65 | Correct | 25 ms | 20256 KB | Output is correct |
66 | Correct | 34 ms | 28116 KB | Output is correct |
67 | Correct | 34 ms | 28120 KB | Output is correct |
68 | Correct | 34 ms | 28476 KB | Output is correct |
69 | Correct | 38 ms | 28652 KB | Output is correct |
70 | Correct | 34 ms | 28592 KB | Output is correct |
71 | Correct | 35 ms | 28016 KB | Output is correct |
72 | Correct | 9 ms | 7372 KB | Output is correct |
73 | Correct | 3 ms | 2112 KB | Output is correct |