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 N 351
int n, k; string s;
int dp[351][351][351], red[351];
void memo(int l, int r, int m){
if(dp[l][r][m] != -1) return;
int already_coll = 0;
if(l != 0) already_coll = red[n - 1] - m - red[r] + red[l - 1];
else already_coll = red[n - 1] - m - red[r];
if(m >= k){
dp[l][r][m] = 0; return;
}
if(already_coll >= k){
dp[l][r][m] = 1; return;
}
if(l == r){
dp[l][r][m] = 0; return;
}
memo(l + 1, r, already_coll); memo(l, r - 1, already_coll);
dp[l][r][m] = (!dp[l + 1][r][already_coll] || !dp[l][r - 1][already_coll]);
}
int main(){
cin >> n >> k >> s;
red[0] = (s[0] == 'C');
memset(dp, -1, sizeof(dp));
for(int i = 1; i < n; i++) red[i] = red[i - 1] + (s[i] == 'C');
memo(0, n - 1, 0);
if(dp[0][n - 1][0]) cout << "DA\n";
else cout << "NE\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |