#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 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
39 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
39 ms |
296 KB |
Output is correct |
13 |
Execution timed out |
1090 ms |
212 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |