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;
int dp[351][351][351];
int arr[351];
int n, k;
int ans (int l, int r, int c, int c2) {
if (c == k || c2 == k) return 1;
int &ret = dp[l][r][c];
if (ret != -1) return ret;
int x = r - l + 1; ret = 0;
if ((x & 1) == (n & 1)) {
ret |= !ans(l + 1, r, c + arr[l], c2);
ret |= !ans(l, r - 1, c + arr[r], c2);
} else {
ret |= !ans(l + 1, r, c, c2 + arr[l]);
ret |= !ans(l, r - 1, c, c2 + arr[r]);
}
return ret;
}
int main () {
memset(dp, -1, sizeof(dp));
cin >> n >> k;
for (int i = 1; i <= n; i++) {
char x; cin >> x; arr[i] = (x == 'C');
}
cout << (ans(1, n, 0, 0) ? "DA\n" : "NE\n");
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |