Submission #775903

# Submission time Handle Problem Language Result Execution time Memory
775903 2023-07-07T06:28:48 Z gun_gan Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
15 / 100
18 ms 13920 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int MX = 407;
 
int N;

vector<vector<ll>> dp[MX][3];
vector<int> R, G, Y;
 
ll f(int r, int g, int y, int c) {
      ll pos = r + g + y, res = 1e18;
      if(dp[r][c][g][y] != -1) return dp[r][c][g][y];
 
      if(pos == N) return dp[r][c][g][y] = 0;
 
      if(c != 0 && r + 1 < R.size()) {
            res = min(res, f(r + 1, g, y, 0) + max(0LL, R[r + 1] - pos - 1));
      }
 
      if(c != 1 && g + 1 < G.size()) {
            res = min(res, f(r, g + 1, y, 1) + max(0LL, G[g + 1] - pos - 1));
      }
      if(c != 2 && y + 1 < Y.size()) {
            res = min(res, f(r, g, y + 1, 2) + max(0LL, Y[y + 1] - pos - 1));
      }
 
      return dp[r][c][g][y] = res;     
}
 
int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);
 
      cin >> N;
      R = {0}, G = {0}, Y = {0};
 
      for(int i = 1; i <= N; i++) {
            char c;
            cin >> c;
 
            if(c == 'R') R.push_back(i);
            if(c == 'G') G.push_back(i);
            if(c == 'Y') Y.push_back(i);
      }

      for(int i = 0; i < MX; i++) {
            for(int c = 0; c < 3; c++) {
                  dp[i][c] = vector<vector<ll>> (G.size() + 1, vector<ll>(Y.size() + 1, -1));
            }
      }
 
      ll k = min({f(0, 0, 0, 0), f(0, 0, 0, 1), f(0, 0, 0, 2)});
      if(k == 1e18) k = -1;

      cout << k << '\n';
}

Compilation message

joi2019_ho_t3.cpp: In function 'll f(int, int, int, int)':
joi2019_ho_t3.cpp:18:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |       if(c != 0 && r + 1 < R.size()) {
      |                    ~~~~~~^~~~~~~~~~
joi2019_ho_t3.cpp:22:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |       if(c != 1 && g + 1 < G.size()) {
      |                    ~~~~~~^~~~~~~~~~
joi2019_ho_t3.cpp:25:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |       if(c != 2 && y + 1 < Y.size()) {
      |                    ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Incorrect 1 ms 1108 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Incorrect 1 ms 1108 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 12 ms 13908 KB Output is correct
3 Correct 13 ms 13848 KB Output is correct
4 Correct 14 ms 13908 KB Output is correct
5 Correct 12 ms 13836 KB Output is correct
6 Correct 13 ms 13908 KB Output is correct
7 Correct 12 ms 13852 KB Output is correct
8 Correct 16 ms 13920 KB Output is correct
9 Correct 12 ms 13808 KB Output is correct
10 Correct 13 ms 13908 KB Output is correct
11 Correct 18 ms 13852 KB Output is correct
12 Correct 8 ms 7380 KB Output is correct
13 Correct 10 ms 9556 KB Output is correct
14 Correct 9 ms 11476 KB Output is correct
15 Correct 12 ms 13868 KB Output is correct
16 Correct 12 ms 13908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Incorrect 1 ms 1108 KB Output isn't correct
12 Halted 0 ms 0 KB -