Submission #818783

# Submission time Handle Problem Language Result Execution time Memory
818783 2023-08-10T06:44:05 Z vjudge1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
20 / 100
500 ms 260536 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MX = 405;

int N;
string s;
int dp[MX][MX][MX];
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][y] != -1) return dp[r][g][y];

      int res = 1e9;
      if(r < R.size() && l != 0) {
            auto gg = upper_bound(G.begin(), G.end(), R[r]) - G.begin();
            auto yy = upper_bound(Y.begin(), Y.end(), R[r]) - Y.begin();

            int cost = max(0, (int)gg - g) + max(0, (int)yy - y);
            res = min(res, f(r + 1, g, y, 0) + cost);
      }
      if(g < G.size() && l != 1) {
            auto rr = upper_bound(R.begin(), R.end(), G[g]) - R.begin();
            auto yy = upper_bound(Y.begin(), Y.end(), G[g]) - Y.begin();

            int cost = max(0, (int)rr - r) + max(0, (int)yy - y);
            res = min(res, f(r, g + 1, y, 1) + cost);
      }
      if(y < Y.size() && l != 2) {
            auto rr = upper_bound(R.begin(), R.end(), Y[y]) - R.begin();
            auto gg = upper_bound(G.begin(), G.end(), Y[y]) - G.begin();

            int cost = max(0, (int)rr - r) + max(0, (int)gg - g);
            res = min(res, f(r, g, y + 1, 2) + cost);
      }

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

      return res;
}

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

      memset(dp, -1, sizeof dp);

      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 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:17:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |       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:31:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |       if(y < Y.size() && l != 2) {
      |          ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 89 ms 260300 KB Output is correct
2 Correct 81 ms 260268 KB Output is correct
3 Correct 83 ms 260256 KB Output is correct
4 Correct 84 ms 260172 KB Output is correct
5 Correct 82 ms 260240 KB Output is correct
6 Correct 87 ms 260248 KB Output is correct
7 Correct 85 ms 260256 KB Output is correct
8 Correct 90 ms 260468 KB Output is correct
9 Correct 85 ms 260220 KB Output is correct
10 Correct 83 ms 260304 KB Output is correct
11 Correct 86 ms 260220 KB Output is correct
12 Correct 85 ms 260300 KB Output is correct
13 Correct 85 ms 260248 KB Output is correct
14 Correct 85 ms 260300 KB Output is correct
15 Correct 85 ms 260244 KB Output is correct
16 Correct 84 ms 260304 KB Output is correct
17 Correct 85 ms 260228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 260300 KB Output is correct
2 Correct 81 ms 260268 KB Output is correct
3 Correct 83 ms 260256 KB Output is correct
4 Correct 84 ms 260172 KB Output is correct
5 Correct 82 ms 260240 KB Output is correct
6 Correct 87 ms 260248 KB Output is correct
7 Correct 85 ms 260256 KB Output is correct
8 Correct 90 ms 260468 KB Output is correct
9 Correct 85 ms 260220 KB Output is correct
10 Correct 83 ms 260304 KB Output is correct
11 Correct 86 ms 260220 KB Output is correct
12 Correct 85 ms 260300 KB Output is correct
13 Correct 85 ms 260248 KB Output is correct
14 Correct 85 ms 260300 KB Output is correct
15 Correct 85 ms 260244 KB Output is correct
16 Correct 84 ms 260304 KB Output is correct
17 Correct 85 ms 260228 KB Output is correct
18 Execution timed out 1105 ms 260296 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 260300 KB Output is correct
2 Correct 84 ms 260328 KB Output is correct
3 Correct 93 ms 260300 KB Output is correct
4 Correct 84 ms 260244 KB Output is correct
5 Correct 84 ms 260332 KB Output is correct
6 Correct 89 ms 260300 KB Output is correct
7 Correct 84 ms 260268 KB Output is correct
8 Correct 86 ms 260260 KB Output is correct
9 Correct 85 ms 260252 KB Output is correct
10 Correct 86 ms 260300 KB Output is correct
11 Correct 89 ms 260536 KB Output is correct
12 Correct 83 ms 260208 KB Output is correct
13 Correct 88 ms 260268 KB Output is correct
14 Correct 84 ms 260252 KB Output is correct
15 Correct 92 ms 260248 KB Output is correct
16 Correct 85 ms 260304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 260300 KB Output is correct
2 Correct 81 ms 260268 KB Output is correct
3 Correct 83 ms 260256 KB Output is correct
4 Correct 84 ms 260172 KB Output is correct
5 Correct 82 ms 260240 KB Output is correct
6 Correct 87 ms 260248 KB Output is correct
7 Correct 85 ms 260256 KB Output is correct
8 Correct 90 ms 260468 KB Output is correct
9 Correct 85 ms 260220 KB Output is correct
10 Correct 83 ms 260304 KB Output is correct
11 Correct 86 ms 260220 KB Output is correct
12 Correct 85 ms 260300 KB Output is correct
13 Correct 85 ms 260248 KB Output is correct
14 Correct 85 ms 260300 KB Output is correct
15 Correct 85 ms 260244 KB Output is correct
16 Correct 84 ms 260304 KB Output is correct
17 Correct 85 ms 260228 KB Output is correct
18 Execution timed out 1105 ms 260296 KB Time limit exceeded
19 Halted 0 ms 0 KB -