#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define vn vector<ll>
using namespace std;
const int MAXN = 352;
int n, k;
char str[MAXN];
int prefix[MAXN];
int dp[MAXN][MAXN][MAXN];
int can_win(int l, int r, int uk) {
    int &res = dp[l][r][uk];
    if (res != -1) return res;
    int total_red = prefix[n - 1];
    int red_left = prefix[r] - (l ? prefix[l - 1] : 0);
    int other_red = total_red - red_left - uk;
    if (uk >= k) return res = 0;
    if (other_red >= k) return res = 1;
    return res = !can_win(l + 1, r, other_red) || !can_win(l, r - 1, other_red);
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        cin >> str[i];
        prefix[i] = (i ? prefix[i - 1] : 0) + (str[i] == 'C');
    }
    memset(dp, -1, sizeof(dp));
    if (can_win(0, n - 1, 0)) {
        cout << "DA" << endl;
    } else {
        cout << "NE" << endl;
    }
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |