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;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
mt19937 rng(123123);
int n,k;
string s;
int tot=0;
int pref[355];
int memo[355][355][355];
int dp(int i,int j,int k){
	if (memo[i][j][k]!=-1) return memo[i][j][k];
	if (k==::k) return memo[i][j][k]=1;
	
	int other=tot-(pref[j]-pref[i-1])-k;
	int res=dp(i+1,j,other+(s[i]=='C'))&dp(i,j-1,other+(s[j]=='C'));
	
	res=1^res;
	
	//cerr<<i<<" "<<j<<" "<<k<<endl;
	return memo[i][j][k]=res;
}
int main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n>>k;
	cin>>s;
	
	s="$"+s;
	
	rep(x,1,n+1){
		pref[x]=pref[x-1]+(s[x]=='C');
	}
	tot=pref[n];
	
	memset(memo,-1,sizeof(memo));
	
	if (dp(1,n,0)) cout<<"DA"<<endl;
	else cout<<"NE"<<endl;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |