#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
int n,k;
string s;
bool jugar(int turno, int antun, int branka,int l,int r){
// Casos Base
if(antun==k) return false;
if(branka==k) return true;
if(s[l]=='P' and s[r]=='P'){
if(turno==0){
return (jugar(1,antun,branka,l+1,r) and jugar(1,antun,branka,l,r-1));
}
else{
return (jugar(0,antun,branka,l+1,r) and jugar(0,antun,branka,l,r-1));
}
}
if(s[l]=='P' and s[r]=='C'){
if(turno==0){
return jugar(1,antun,branka,l+1,r);
}
else{
return (jugar(0,antun,branka,l+1,r));
}
}
if(s[l]=='C' and s[r]=='P'){
if(turno==0){
return jugar(1,antun,branka,l,r-1);
}
else{
return (jugar(0,antun,branka,l,r-1));
}
}
if(s[l]=='C' and s[r]=='C'){
if(turno==0){
return (jugar(1,antun+1,branka,l+1,r) and jugar(1,antun+1,branka,l,r-1));
}
else{
return (jugar(0,antun,branka+1,l+1,r) and jugar(0,antun,branka+1,l,r-1));
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>k;
cin>>s;
if(jugar(0,0,0,0,s.size()-1)) cout<<"DA\n";
else cout<<"NE\n";
//cout<<jugar(0,0,0,0,s.size()-1)<<"\n";
return 0;
}
Compilation message
Main.cpp: In function 'bool jugar(int, int, int, int, int)':
Main.cpp:48:1: warning: control reaches end of non-void function [-Wreturn-type]
48 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |