답안 #747704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747704 2023-05-24T14:00:48 Z tch1cherin Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
15 / 100
19 ms 3800 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int R = count(s.begin(), s.end(), 'R');
  int G = count(s.begin(), s.end(), 'G');
  int Y = count(s.begin(), s.end(), 'Y');
  vector<int> red(n + 1), green(n + 1), yellow(n + 1);
  for (int i = 0; i < n; i++) {
    red[i + 1] = red[i] + (int)(s[i] == 'R');
    green[i + 1] = green[i] + (int)(s[i] == 'G');
    yellow[i + 1] = yellow[i] + (int)(s[i] == 'Y');
  }
  vector dp(R + 1, vector(G + 1, vector(Y + 1, vector<int>(4, INF))));
  dp[R][G][Y][3] = 0;
  for (int i = n; i > 0; i--) {
    for (int r = 0; r <= R; r++) {
      for (int g = 0; g <= G && r + g <= i; g++) {
        int y = i - r - g;
        if (y > Y) {
          continue;
        }
        for (int l = 0; l < 4; l++) {
          int Rq = red[i - 1], Gq = green[i - 1], Yq = yellow[i - 1]; 
          if (l != 0 && r > 0) {
            dp[r - 1][g][y][0] = min(dp[r - 1][g][y][0], dp[r][g][y][l] + abs(Rq - (r - 1)) + abs(Gq - g) + abs(Yq - y));
          }
          if (l != 1 && g > 0) {
            dp[r][g - 1][y][1] = min(dp[r][g - 1][y][1], dp[r][g][y][l] + abs(Rq - r) + abs(Gq - (g - 1)) + abs(Yq - y));
          }
          if (l != 2 && y > 0) {
            dp[r][g][y - 1][2] = min(dp[r][g][y - 1][2], dp[r][g][y][l] + abs(Rq - r) + abs(Gq - g) + abs(Yq - (y - 1)));
          }
        }
      } 
    }
  }
  int ans = min({dp[0][0][0][0], dp[0][0][0][1], dp[0][0][0][2]});
  cout << (ans == INF ? -1 : ans / 2) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 3796 KB Output is correct
3 Correct 16 ms 3788 KB Output is correct
4 Correct 16 ms 3796 KB Output is correct
5 Correct 16 ms 3796 KB Output is correct
6 Correct 16 ms 3800 KB Output is correct
7 Correct 15 ms 3668 KB Output is correct
8 Correct 16 ms 3668 KB Output is correct
9 Correct 17 ms 3668 KB Output is correct
10 Correct 19 ms 3800 KB Output is correct
11 Correct 16 ms 3796 KB Output is correct
12 Correct 4 ms 1236 KB Output is correct
13 Correct 6 ms 1956 KB Output is correct
14 Correct 9 ms 2644 KB Output is correct
15 Correct 15 ms 3796 KB Output is correct
16 Correct 16 ms 3796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -