답안 #587732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587732 2022-07-02T09:40:47 Z MilosMilutinovic Kamenčići (COCI21_kamencici) C++14
70 / 70
68 ms 85456 KB
/**                                                           
 *    author:  wxhtzdy
 *    created: 02.07.2022 11:24:43
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> a(n + 1);
  for (int i = 0; i < n; i++) {
    a[i + 1] = (s[i] == 'C' ? 1 : 0);  
  }
  vector<int> pref(n + 1);
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + a[i];
  }
  vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(n + 1, vector<int>(k, -1)));
  function<bool(int, int, int)> Solve = [&](int l, int r, int c) {
    if (c == k) {
      return false;  
    }
    if (l > r) {
      assert(false);
      return true;
    }
    if (dp[l][r][c] != -1) {
      return (dp[l][r][c] == 1);
    }                       
    bool ok = false;
    if (c + a[l] < k) {
      ok = ok | (!Solve(l + 1, r, pref[l] + pref[n] - pref[r] - c - a[l]));
    }
    if (c + a[r] < k) {
      ok = ok | (!Solve(l, r - 1, pref[l - 1] + pref[n] - pref[r - 1] - c - a[r]));
    }
    dp[l][r][c] = ok;
    return ok;
  };     
  cout << (Solve(1, n, 0) ? "DA" : "NE") << '\n'; 
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 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 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 444 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 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 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 444 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 17 ms 18644 KB Output is correct
14 Correct 68 ms 24404 KB Output is correct
15 Correct 15 ms 13396 KB Output is correct
16 Correct 66 ms 54420 KB Output is correct
17 Correct 59 ms 85456 KB Output is correct
18 Correct 40 ms 54524 KB Output is correct