#include "bits/stdc++.h"
using namespace std;
int autun = 0, branka = 0;
string s;
int n, k;
bool jugar(int turno, int auntun, int branka, int l, int r){
if(auntun == k) return 0;
if(branka == k) return 1;
if(s[l] == 'P' and s[r] == 'P'){
if(turno == 0){
return jugar(1, auntun, branka, l + 1, r) or jugar(1, auntun, branka, l, r + 1);
} else {
return (jugar(0, auntun, branka, l + 1, r) and jugar(0, auntun, branka, l, r + 1));
}
}
if(s[l] == 'P' and s[r] == 'C'){
if(turno == 0){
return jugar(1, auntun, branka, l + 1, r);
} else {
return jugar(0, auntun, branka, l + 1, r);
}
}
if(s[l] == 'C' and s[r] == 'P'){
if(turno == 0){
return jugar(1, auntun, branka, l, r - 1);
} else {
return jugar(0, auntun, branka, l, r - 1);
}
}
if(s[l] == 'C' and s[r] == 'C'){
if(turno == 0){
return jugar(1, auntun + 1, branka, l + 1, r) or jugar(1, auntun + 1, branka, l, r - 1);
} else {
return (jugar(0, auntun, branka + 1, l + 1, r) and jugar(0, auntun, branka + 1, l, r - 1));
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k>>s;
if(jugar(0, 0, 0, 0, s.size() - 1)) cout<<"DA";
else cout<<"NE";
return 0;
}
Compilation message
Main.cpp: In function 'bool jugar(int, int, int, int, int)':
Main.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
37 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |