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;
const int MX = 355;
int n, k;
string s; 
int pre[MX], suf[MX];
int getRed(int l, int r) {
	return pre[l-1] + suf[r+1];
}
bool vis[MX][MX][MX][2], dp[MX][MX][MX][2];
bool solve(int l, int r, int red, int who) {
	bool &ret = dp[l][r][red][who];
	if(vis[l][r][red][who]) return ret;
	vis[l][r][red][who] = 1;
	int oppred = getRed(l, r)-red;
	if(s[l]!='C' || red+1<k) ret |= solve(l+1, r, oppred, who^1)==0;
	if(s[r]!='C' || red+1<k) ret |= solve(l, r-1, oppred, who^1)==0;
	return ret;
}
void PlayGround() {
	cin >> n >> k;
	cin >> s;
	s = "#" + s;
	for(int i=1; i<=n; ++i) {
		pre[i] = pre[i-1] + (s[i]=='C');
	}
	for(int i=n; i; --i) {
		suf[i] = suf[i+1] + (s[i]=='C');
	}
	if(solve(1, n, 0, 1)) cout << "DA\n";
	else cout << "NE\n";
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	PlayGround();
	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... |