답안 #506375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
506375 2022-01-12T02:59:20 Z sidon Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
301 ms 97164 KB
#include <bits/stdc++.h>
using namespace std;
#define minim(X, Y) (X = min(X, Y))
#define F(X, Y) for(int X = 0; X < Y; X++)
#define g(X) (X ? (X > 1 ? z : y) : x)

const int Z = 202, INF = 1e9;

int N, A[Z*2], DP[Z][Z][Z][3], p[3][Z*2], h[3][Z*2], c[3], x, y, z;

int main() {
	cin >> N, getchar();
	F(i, N) {
		char v = getchar();
		A[i] = (v < 82) + (v < 89);
	}

	F(i, Z) F(j, Z) F(k, Z) F(l, 3)
		DP[i][j][k][l] = (i || j || k) ? INF : 0;

	F(i, N) {
		if(++c[A[i]] >= Z-1) break;
		p[A[i]][g(A[i]) = c[A[i]]] = i;
		F(j, 3) h[j][i] = c[j];

		F(j, i+1) F(k, i+1) F(o, 3) {
			(A[i] ? x : y) = j;
			(A[i] < 2 ? z : y) = k;
			if(x > c[0] || y > c[1] || z > c[2]) continue;
			int &w = g(o), a = INF, b = 0;
			if(!w) continue; --w;
			F(r, 3) minim(a, r != o ? DP[x][y][z][r] : INF); ++w;
			F(r, 3) b += r != o ? max(0, g(r) - h[r][p[o][w]]) : 0;
			minim(DP[x][y][z][o], a + b);
		}
	}
	int res = INF;
	F(i, 3) minim(res, DP[c[0]][c[1]][c[2]][i]);

	cout << (res == INF ? -1 : res);
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:31:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   31 |    if(!w) continue; --w;
      |    ^~
joi2019_ho_t3.cpp:31:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   31 |    if(!w) continue; --w;
      |                     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 96964 KB Output is correct
2 Correct 45 ms 97016 KB Output is correct
3 Correct 46 ms 97060 KB Output is correct
4 Correct 43 ms 96952 KB Output is correct
5 Correct 44 ms 96944 KB Output is correct
6 Correct 58 ms 96968 KB Output is correct
7 Correct 46 ms 97044 KB Output is correct
8 Correct 46 ms 96996 KB Output is correct
9 Correct 43 ms 97036 KB Output is correct
10 Correct 46 ms 96976 KB Output is correct
11 Correct 44 ms 96952 KB Output is correct
12 Correct 45 ms 96960 KB Output is correct
13 Correct 53 ms 97076 KB Output is correct
14 Correct 43 ms 96948 KB Output is correct
15 Correct 43 ms 97000 KB Output is correct
16 Correct 44 ms 96964 KB Output is correct
17 Correct 48 ms 97000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 96964 KB Output is correct
2 Correct 45 ms 97016 KB Output is correct
3 Correct 46 ms 97060 KB Output is correct
4 Correct 43 ms 96952 KB Output is correct
5 Correct 44 ms 96944 KB Output is correct
6 Correct 58 ms 96968 KB Output is correct
7 Correct 46 ms 97044 KB Output is correct
8 Correct 46 ms 96996 KB Output is correct
9 Correct 43 ms 97036 KB Output is correct
10 Correct 46 ms 96976 KB Output is correct
11 Correct 44 ms 96952 KB Output is correct
12 Correct 45 ms 96960 KB Output is correct
13 Correct 53 ms 97076 KB Output is correct
14 Correct 43 ms 96948 KB Output is correct
15 Correct 43 ms 97000 KB Output is correct
16 Correct 44 ms 96964 KB Output is correct
17 Correct 48 ms 97000 KB Output is correct
18 Correct 45 ms 97040 KB Output is correct
19 Correct 48 ms 96976 KB Output is correct
20 Correct 44 ms 97000 KB Output is correct
21 Correct 54 ms 97036 KB Output is correct
22 Correct 46 ms 97044 KB Output is correct
23 Correct 46 ms 97048 KB Output is correct
24 Correct 49 ms 97056 KB Output is correct
25 Correct 49 ms 96968 KB Output is correct
26 Correct 44 ms 96952 KB Output is correct
27 Correct 43 ms 97052 KB Output is correct
28 Correct 44 ms 97008 KB Output is correct
29 Correct 48 ms 96980 KB Output is correct
30 Correct 45 ms 96980 KB Output is correct
31 Correct 50 ms 97028 KB Output is correct
32 Correct 45 ms 97028 KB Output is correct
33 Correct 47 ms 97028 KB Output is correct
34 Correct 54 ms 97040 KB Output is correct
35 Correct 45 ms 97140 KB Output is correct
36 Correct 45 ms 96976 KB Output is correct
37 Correct 58 ms 97008 KB Output is correct
38 Correct 47 ms 97020 KB Output is correct
39 Correct 47 ms 96968 KB Output is correct
40 Correct 44 ms 96960 KB Output is correct
41 Correct 45 ms 96968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 96968 KB Output is correct
2 Correct 199 ms 97084 KB Output is correct
3 Correct 186 ms 97064 KB Output is correct
4 Correct 168 ms 97064 KB Output is correct
5 Correct 176 ms 97068 KB Output is correct
6 Correct 182 ms 97164 KB Output is correct
7 Correct 177 ms 96992 KB Output is correct
8 Correct 179 ms 96964 KB Output is correct
9 Correct 195 ms 97060 KB Output is correct
10 Correct 184 ms 97044 KB Output is correct
11 Correct 165 ms 96964 KB Output is correct
12 Correct 68 ms 96964 KB Output is correct
13 Correct 96 ms 96940 KB Output is correct
14 Correct 134 ms 97152 KB Output is correct
15 Correct 169 ms 96964 KB Output is correct
16 Correct 192 ms 97000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 96964 KB Output is correct
2 Correct 45 ms 97016 KB Output is correct
3 Correct 46 ms 97060 KB Output is correct
4 Correct 43 ms 96952 KB Output is correct
5 Correct 44 ms 96944 KB Output is correct
6 Correct 58 ms 96968 KB Output is correct
7 Correct 46 ms 97044 KB Output is correct
8 Correct 46 ms 96996 KB Output is correct
9 Correct 43 ms 97036 KB Output is correct
10 Correct 46 ms 96976 KB Output is correct
11 Correct 44 ms 96952 KB Output is correct
12 Correct 45 ms 96960 KB Output is correct
13 Correct 53 ms 97076 KB Output is correct
14 Correct 43 ms 96948 KB Output is correct
15 Correct 43 ms 97000 KB Output is correct
16 Correct 44 ms 96964 KB Output is correct
17 Correct 48 ms 97000 KB Output is correct
18 Correct 45 ms 97040 KB Output is correct
19 Correct 48 ms 96976 KB Output is correct
20 Correct 44 ms 97000 KB Output is correct
21 Correct 54 ms 97036 KB Output is correct
22 Correct 46 ms 97044 KB Output is correct
23 Correct 46 ms 97048 KB Output is correct
24 Correct 49 ms 97056 KB Output is correct
25 Correct 49 ms 96968 KB Output is correct
26 Correct 44 ms 96952 KB Output is correct
27 Correct 43 ms 97052 KB Output is correct
28 Correct 44 ms 97008 KB Output is correct
29 Correct 48 ms 96980 KB Output is correct
30 Correct 45 ms 96980 KB Output is correct
31 Correct 50 ms 97028 KB Output is correct
32 Correct 45 ms 97028 KB Output is correct
33 Correct 47 ms 97028 KB Output is correct
34 Correct 54 ms 97040 KB Output is correct
35 Correct 45 ms 97140 KB Output is correct
36 Correct 45 ms 96976 KB Output is correct
37 Correct 58 ms 97008 KB Output is correct
38 Correct 47 ms 97020 KB Output is correct
39 Correct 47 ms 96968 KB Output is correct
40 Correct 44 ms 96960 KB Output is correct
41 Correct 45 ms 96968 KB Output is correct
42 Correct 44 ms 96968 KB Output is correct
43 Correct 199 ms 97084 KB Output is correct
44 Correct 186 ms 97064 KB Output is correct
45 Correct 168 ms 97064 KB Output is correct
46 Correct 176 ms 97068 KB Output is correct
47 Correct 182 ms 97164 KB Output is correct
48 Correct 177 ms 96992 KB Output is correct
49 Correct 179 ms 96964 KB Output is correct
50 Correct 195 ms 97060 KB Output is correct
51 Correct 184 ms 97044 KB Output is correct
52 Correct 165 ms 96964 KB Output is correct
53 Correct 68 ms 96964 KB Output is correct
54 Correct 96 ms 96940 KB Output is correct
55 Correct 134 ms 97152 KB Output is correct
56 Correct 169 ms 96964 KB Output is correct
57 Correct 192 ms 97000 KB Output is correct
58 Correct 241 ms 97060 KB Output is correct
59 Correct 251 ms 97128 KB Output is correct
60 Correct 274 ms 97060 KB Output is correct
61 Correct 245 ms 97064 KB Output is correct
62 Correct 169 ms 97016 KB Output is correct
63 Correct 204 ms 97056 KB Output is correct
64 Correct 218 ms 97092 KB Output is correct
65 Correct 222 ms 97068 KB Output is correct
66 Correct 293 ms 97064 KB Output is correct
67 Correct 219 ms 97068 KB Output is correct
68 Correct 301 ms 97068 KB Output is correct
69 Correct 256 ms 97132 KB Output is correct
70 Correct 269 ms 97068 KB Output is correct
71 Correct 256 ms 96952 KB Output is correct
72 Correct 88 ms 97060 KB Output is correct
73 Correct 78 ms 97008 KB Output is correct