#include <bits/stdc++.h>
using std::vector;
template <class F> struct RecLambda : private F {
explicit RecLambda(F&& f) : F(std::forward<F>(f)) {}
template <class... Args> decltype(auto) operator()(Args&&... args) const {
return F::operator()(*this, std::forward<Args>(args)...);
}
};
int main() {
int N, K;
std::cin >> N >> K;
vector<char> S(N);
for (auto& x : S) {
std::cin >> x;
}
vector<int> red(N + 1);
for (int i = 0; i < N; ++i) {
red[i + 1] = red[i] + (S[i] == 'C');
}
vector memo(N, vector(N + 1, vector<int>(K, -1)));
std::cout << (RecLambda([&](auto&& dfs, const int l, const int r, const int k) -> int {
if (k >= K) return 0;
const int other = red[l] + (red[N] - red[r]) - k;
if (other >= K) return 1;
if (memo[l][r][k] != -1) return memo[l][r][k];
if (dfs(l + 1, r, other) == 0) return memo[l][r][k] = 1;
if (dfs(l, r - 1, other) == 0) return memo[l][r][k] = 1;
return memo[l][r][k] = 0;
})(0, N, 0) ? "DA" : "NE") << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
416 KB |
Output is correct |
8 |
Correct |
1 ms |
292 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
416 KB |
Output is correct |
8 |
Correct |
1 ms |
292 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
532 KB |
Output is correct |
13 |
Correct |
14 ms |
18592 KB |
Output is correct |
14 |
Correct |
27 ms |
24228 KB |
Output is correct |
15 |
Correct |
11 ms |
13260 KB |
Output is correct |
16 |
Correct |
39 ms |
54348 KB |
Output is correct |
17 |
Correct |
46 ms |
85132 KB |
Output is correct |
18 |
Correct |
38 ms |
54256 KB |
Output is correct |