This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int maxn = 351;
const int oo = 1e9 + 7;
const ll inf = 1e18;
int n, k, tol = 0;
int pre[maxn], dp[maxn][maxn][maxn];
int recursive(int l, int r, int m) {
    if (m >= k) {
        dp[l][r][m] = 0;
        return 0;
    }
        
    int h = tol - m - (pre[r] - pre[l - 1]);
    if (h >= k) {
        dp[l][r][m] = 1;
        return 1;
    }
    if (dp[l][r][m] != -1)
        return dp[l][r][m];
    dp[l][r][m] = (!recursive(l + 1, r, h) | !recursive(l, r - 1, h));
    return dp[l][r][m];
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> k;
    string s;
    cin >> s;
    s = ' ' + s;
    for (int i = 1; i <= n; i++) {
        pre[i] = pre[i - 1] + (s[i] == 'C');
        if (s[i] == 'C')
            tol++;
    }
    for (int i = 0; i < maxn; i++) {
        for (int j = 0; j < maxn; j++) {
            for (int k = 0; k < maxn; k++)
                dp[i][j][k] = -1;
        }
    }
    if (recursive(1, n, 0))
        cout << "DA";
    else    
        cout << "NE";
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |