답안 #818875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
818875 2023-08-10T07:07:58 Z vjudge1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
75 / 100
500 ms 775804 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MX = 405;

int N;
string s;

vector < int > dp[MX][MX][4];

int cnt[MX][3]; //R = 0, G = 1, Y = 2
vector<int> R, G, Y;

int f(int r, int g, int y, int l) {
      if(r + g + y == N) return 0;
      if(dp[r][g][l][y] != -1) return dp[r][g][l][y];

      int res = 1e9;
      if(r < R.size() && l != 0) {
            int cost = max(0, cnt[R[r]][1] - g) + max(0, cnt[R[r]][2] - y);
            res = min(res, f(r + 1, g, y, 0) + cost);
      }
      if(g < G.size() && l != 1) {
            int cost = max(0, cnt[G[g]][0] - r) + max(0, cnt[G[g]][2] - y);
            res = min(res, f(r, g + 1, y, 1) + cost);
      }
      if(y < Y.size() && l != 2) {
            int cost = max(0, cnt[Y[y]][0] - r) + max(0, cnt[Y[y]][1] - g);
            res = min(res, f(r, g, y + 1, 2) + cost);
      }

      // cout << r << " " << g << " " << y << " = " << res << '\n';

      return dp[r][g][l][y] = res;
}

int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);

      cin >> N >> s;

      for(int i = 0; i < N; i++) {
            if(s[i] == 'R') {
                  R.push_back(i);
                  cnt[i][0]++;
            }
            if(s[i] == 'G') {
                  G.push_back(i);
                  cnt[i][1]++;
            }
            if(s[i] == 'Y') {
                  Y.push_back(i);
                  cnt[i][2]++;
            }

            if(i > 0) {
                  cnt[i][0] += cnt[i - 1][0];
                  cnt[i][1] += cnt[i - 1][1];
                  cnt[i][2] += cnt[i - 1][2];
            }
      }

      for(int i = 0; i < MX; i++)
            for(int j = 0; j < MX; j++) 
                  for(int c = 0; c < 4; c++)
                        dp[i][j][c].assign(Y.size() + 1, -1);

      int k = f(0, 0, 0, 3);
      if(k == 1e9) k = -1;
      cout << k << '\n';
}

Compilation message

joi2019_ho_t3.cpp: In function 'int f(int, int, int, int)':
joi2019_ho_t3.cpp:20:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |       if(r < R.size() && l != 0) {
      |          ~~^~~~~~~~~~
joi2019_ho_t3.cpp:24:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |       if(g < G.size() && l != 1) {
      |          ~~^~~~~~~~~~
joi2019_ho_t3.cpp:28:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |       if(y < Y.size() && l != 2) {
      |          ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 36172 KB Output is correct
2 Correct 31 ms 36272 KB Output is correct
3 Correct 36 ms 36220 KB Output is correct
4 Correct 36 ms 36312 KB Output is correct
5 Correct 36 ms 46528 KB Output is correct
6 Correct 36 ms 36172 KB Output is correct
7 Correct 35 ms 36280 KB Output is correct
8 Correct 38 ms 36168 KB Output is correct
9 Correct 36 ms 36236 KB Output is correct
10 Correct 41 ms 36260 KB Output is correct
11 Correct 35 ms 36236 KB Output is correct
12 Correct 34 ms 36180 KB Output is correct
13 Correct 36 ms 46452 KB Output is correct
14 Correct 35 ms 36256 KB Output is correct
15 Correct 38 ms 46408 KB Output is correct
16 Correct 36 ms 36148 KB Output is correct
17 Correct 42 ms 56764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 36172 KB Output is correct
2 Correct 31 ms 36272 KB Output is correct
3 Correct 36 ms 36220 KB Output is correct
4 Correct 36 ms 36312 KB Output is correct
5 Correct 36 ms 46528 KB Output is correct
6 Correct 36 ms 36172 KB Output is correct
7 Correct 35 ms 36280 KB Output is correct
8 Correct 38 ms 36168 KB Output is correct
9 Correct 36 ms 36236 KB Output is correct
10 Correct 41 ms 36260 KB Output is correct
11 Correct 35 ms 36236 KB Output is correct
12 Correct 34 ms 36180 KB Output is correct
13 Correct 36 ms 46452 KB Output is correct
14 Correct 35 ms 36256 KB Output is correct
15 Correct 38 ms 46408 KB Output is correct
16 Correct 36 ms 36148 KB Output is correct
17 Correct 42 ms 56764 KB Output is correct
18 Correct 54 ms 77324 KB Output is correct
19 Correct 54 ms 87556 KB Output is correct
20 Correct 49 ms 77308 KB Output is correct
21 Correct 49 ms 77260 KB Output is correct
22 Correct 55 ms 87556 KB Output is correct
23 Correct 50 ms 77304 KB Output is correct
24 Correct 55 ms 87544 KB Output is correct
25 Correct 32 ms 36204 KB Output is correct
26 Correct 31 ms 36180 KB Output is correct
27 Correct 40 ms 56748 KB Output is correct
28 Correct 57 ms 77260 KB Output is correct
29 Correct 53 ms 77228 KB Output is correct
30 Correct 49 ms 77284 KB Output is correct
31 Correct 64 ms 87612 KB Output is correct
32 Correct 50 ms 77320 KB Output is correct
33 Correct 35 ms 36260 KB Output is correct
34 Correct 36 ms 36224 KB Output is correct
35 Correct 48 ms 56776 KB Output is correct
36 Correct 53 ms 87524 KB Output is correct
37 Correct 55 ms 87496 KB Output is correct
38 Correct 59 ms 77316 KB Output is correct
39 Correct 50 ms 77252 KB Output is correct
40 Correct 78 ms 128588 KB Output is correct
41 Correct 49 ms 46424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 36216 KB Output is correct
2 Correct 31 ms 36236 KB Output is correct
3 Correct 32 ms 36292 KB Output is correct
4 Correct 31 ms 36312 KB Output is correct
5 Correct 31 ms 36312 KB Output is correct
6 Correct 31 ms 36204 KB Output is correct
7 Correct 36 ms 36268 KB Output is correct
8 Correct 41 ms 36236 KB Output is correct
9 Correct 39 ms 36172 KB Output is correct
10 Correct 35 ms 36220 KB Output is correct
11 Correct 32 ms 36212 KB Output is correct
12 Correct 31 ms 36188 KB Output is correct
13 Correct 31 ms 36284 KB Output is correct
14 Correct 31 ms 36204 KB Output is correct
15 Correct 32 ms 36248 KB Output is correct
16 Correct 31 ms 36300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 36172 KB Output is correct
2 Correct 31 ms 36272 KB Output is correct
3 Correct 36 ms 36220 KB Output is correct
4 Correct 36 ms 36312 KB Output is correct
5 Correct 36 ms 46528 KB Output is correct
6 Correct 36 ms 36172 KB Output is correct
7 Correct 35 ms 36280 KB Output is correct
8 Correct 38 ms 36168 KB Output is correct
9 Correct 36 ms 36236 KB Output is correct
10 Correct 41 ms 36260 KB Output is correct
11 Correct 35 ms 36236 KB Output is correct
12 Correct 34 ms 36180 KB Output is correct
13 Correct 36 ms 46452 KB Output is correct
14 Correct 35 ms 36256 KB Output is correct
15 Correct 38 ms 46408 KB Output is correct
16 Correct 36 ms 36148 KB Output is correct
17 Correct 42 ms 56764 KB Output is correct
18 Correct 54 ms 77324 KB Output is correct
19 Correct 54 ms 87556 KB Output is correct
20 Correct 49 ms 77308 KB Output is correct
21 Correct 49 ms 77260 KB Output is correct
22 Correct 55 ms 87556 KB Output is correct
23 Correct 50 ms 77304 KB Output is correct
24 Correct 55 ms 87544 KB Output is correct
25 Correct 32 ms 36204 KB Output is correct
26 Correct 31 ms 36180 KB Output is correct
27 Correct 40 ms 56748 KB Output is correct
28 Correct 57 ms 77260 KB Output is correct
29 Correct 53 ms 77228 KB Output is correct
30 Correct 49 ms 77284 KB Output is correct
31 Correct 64 ms 87612 KB Output is correct
32 Correct 50 ms 77320 KB Output is correct
33 Correct 35 ms 36260 KB Output is correct
34 Correct 36 ms 36224 KB Output is correct
35 Correct 48 ms 56776 KB Output is correct
36 Correct 53 ms 87524 KB Output is correct
37 Correct 55 ms 87496 KB Output is correct
38 Correct 59 ms 77316 KB Output is correct
39 Correct 50 ms 77252 KB Output is correct
40 Correct 78 ms 128588 KB Output is correct
41 Correct 49 ms 46424 KB Output is correct
42 Correct 31 ms 36216 KB Output is correct
43 Correct 31 ms 36236 KB Output is correct
44 Correct 32 ms 36292 KB Output is correct
45 Correct 31 ms 36312 KB Output is correct
46 Correct 31 ms 36312 KB Output is correct
47 Correct 31 ms 36204 KB Output is correct
48 Correct 36 ms 36268 KB Output is correct
49 Correct 41 ms 36236 KB Output is correct
50 Correct 39 ms 36172 KB Output is correct
51 Correct 35 ms 36220 KB Output is correct
52 Correct 32 ms 36212 KB Output is correct
53 Correct 31 ms 36188 KB Output is correct
54 Correct 31 ms 36284 KB Output is correct
55 Correct 31 ms 36204 KB Output is correct
56 Correct 32 ms 36248 KB Output is correct
57 Correct 31 ms 36300 KB Output is correct
58 Correct 298 ms 416348 KB Output is correct
59 Correct 218 ms 334064 KB Output is correct
60 Correct 240 ms 354656 KB Output is correct
61 Correct 274 ms 375288 KB Output is correct
62 Correct 35 ms 36300 KB Output is correct
63 Correct 38 ms 46568 KB Output is correct
64 Correct 99 ms 118388 KB Output is correct
65 Correct 118 ms 169764 KB Output is correct
66 Correct 277 ms 364984 KB Output is correct
67 Correct 238 ms 375256 KB Output is correct
68 Correct 248 ms 354660 KB Output is correct
69 Correct 239 ms 375260 KB Output is correct
70 Correct 219 ms 344396 KB Output is correct
71 Correct 259 ms 375252 KB Output is correct
72 Correct 101 ms 210868 KB Output is correct
73 Execution timed out 539 ms 775804 KB Time limit exceeded
74 Halted 0 ms 0 KB -