#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define float double
bool ans(0);
int n, k;
string s;
void bk(int L, int R, bool trn, int cA, int cB){
if(cA>=k)return;
if(cB>=k){
ans=1;
return;
}
if(trn){
if(s[L]=='P'){
bk(L+1, R, !trn, cA, cB);
}
if(s[R]=='P'){
bk(L, R-1, !trn, cA, cB);
}
else if(s[L]=='C' && s[R]=='C'){
bk(L+1, R, !trn, cA, cB + (s[L]=='C') );
bk(L, R-1, !trn, cA, cB + (s[R]=='C') );
}
}
else{
if(s[L]=='P'){
bk(L+1, R, !trn, cA, cB);
}
if(s[R]=='P'){
bk(L, R-1, !trn, cA, cB);
}
else if(s[L]=='C' && s[R]=='C'){
bk(L+1, R, !trn, cA + (s[L]=='C'), cB );
bk(L, R-1, !trn, cA + (s[R]=='C'), cB );
}
}
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>k;
cin>>s;
bk(0, n-1, 0, 0, 0);
if(ans)cout<<"DA"<<endl;
else cout<<"NE"<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |