#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 |
1 |
Correct |
45 ms |
169424 KB |
Output is correct |
2 |
Correct |
43 ms |
169552 KB |
Output is correct |
3 |
Correct |
44 ms |
169552 KB |
Output is correct |
4 |
Correct |
47 ms |
169672 KB |
Output is correct |
5 |
Correct |
52 ms |
169592 KB |
Output is correct |
6 |
Correct |
58 ms |
169556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
169424 KB |
Output is correct |
2 |
Correct |
43 ms |
169552 KB |
Output is correct |
3 |
Correct |
44 ms |
169552 KB |
Output is correct |
4 |
Correct |
47 ms |
169672 KB |
Output is correct |
5 |
Correct |
52 ms |
169592 KB |
Output is correct |
6 |
Correct |
58 ms |
169556 KB |
Output is correct |
7 |
Correct |
42 ms |
169560 KB |
Output is correct |
8 |
Correct |
43 ms |
169556 KB |
Output is correct |
9 |
Correct |
43 ms |
169616 KB |
Output is correct |
10 |
Correct |
48 ms |
169524 KB |
Output is correct |
11 |
Correct |
42 ms |
169516 KB |
Output is correct |
12 |
Correct |
44 ms |
169556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
169424 KB |
Output is correct |
2 |
Correct |
43 ms |
169552 KB |
Output is correct |
3 |
Correct |
44 ms |
169552 KB |
Output is correct |
4 |
Correct |
47 ms |
169672 KB |
Output is correct |
5 |
Correct |
52 ms |
169592 KB |
Output is correct |
6 |
Correct |
58 ms |
169556 KB |
Output is correct |
7 |
Correct |
42 ms |
169560 KB |
Output is correct |
8 |
Correct |
43 ms |
169556 KB |
Output is correct |
9 |
Correct |
43 ms |
169616 KB |
Output is correct |
10 |
Correct |
48 ms |
169524 KB |
Output is correct |
11 |
Correct |
42 ms |
169516 KB |
Output is correct |
12 |
Correct |
44 ms |
169556 KB |
Output is correct |
13 |
Correct |
42 ms |
169572 KB |
Output is correct |
14 |
Correct |
56 ms |
169552 KB |
Output is correct |
15 |
Correct |
48 ms |
169900 KB |
Output is correct |
16 |
Correct |
55 ms |
169656 KB |
Output is correct |
17 |
Correct |
48 ms |
169556 KB |
Output is correct |
18 |
Correct |
45 ms |
169552 KB |
Output is correct |