This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int n,k;
string s;
int dp[305][305][305];
vector<int> prefix, suffix;
int solve(int l,int r,int cnt){
bool turn = (l + n-r-1)&1;
if(l>r) return turn;
if(cnt==k) return (turn);
int rem = prefix[l] + suffix[r] - cnt;
if(rem == k) return !turn;
int &ret = dp[l][r][cnt];
if(~ret) return ret;
bool c1 = solve(l+1,r,cnt+(s[l]=='C'&&!turn));
bool c2 = solve(l,r-1,cnt+(s[r]=='C'&&!turn));
return ret = !(c1&c2);
}
void solve(){
cin>>n>>k;
cin>>s;
prefix.resize(n), suffix.resize(n);
for(int i=1;i<=n;i++) prefix[i] = (s[i-1] == 'C') + prefix[i-1];
for(int i=n-2;i>=0;i--) suffix[i] = (s[i+1] == 'C') + suffix[i+1];
memset(dp,-1,sizeof(dp));
cout<<(solve(0,n-1,0)?"DA":"NE")<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |