#include<bits/stdc++.h>
using namespace std;
int n, k;
string s;
bool fun(int l = 0, int r = n - 1, int a = 0, int b = 0)
{
if(a == k || b == k)
return b == k;
if(!(n - (r - l + 1) & 1))
{
return fun(l + 1, r, a + (s[l] == 'C'), b) || fun(l, r - 1, a + (s[r] == 'C'), b);
}
else
{
return !(!fun(l + 1, r, a, b + (s[l] == 'C')) || !fun(l, r - 1, a, b + (s[r] == 'C')));
}
}
int main()
{
cin>>n>>k;
cin>>s;
cout<<(fun() ? "DA" : "NE");
}
Compilation message
Main.cpp: In function 'bool fun(int, int, int, int)':
Main.cpp:9:12: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
9 | if(!(n - (r - l + 1) & 1))
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
310 ms |
280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
310 ms |
280 KB |
Output is correct |
13 |
Correct |
965 ms |
276 KB |
Output is correct |
14 |
Execution timed out |
1091 ms |
212 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |