This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* 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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |