Submission #587724

# Submission time Handle Problem Language Result Execution time Memory
587724 2022-07-02T09:36:48 Z MilosMilutinovic Kamenčići (COCI21_kamencici) C++14
10 / 70
1 ms 440 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 (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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -