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 N = 350 + 5;
int n, k, prefix[N], sum;
string str;
bool dp[N][N][N];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> k;
cin >> str;
str = '$' + str;
for(int i = 1; i <= n; i++) prefix[i] = prefix[i - 1] + (str[i] == 'C');
for(int l = n; l >= 1; l--){
for(int r = l; r <= n; r++){
sum = prefix[n] - (prefix[r] - prefix[l - 1]);
for(int i = 0; i < k; i++){
int j = sum - i;
if(j >= k) dp[l][r][i] = true;
else{
if(!dp[l + 1][r][j] || !dp[l][r - 1][j]) dp[l][r][i] = true;
else dp[l][r][i] = false;
}
}
}
}
cout << (dp[1][n][0] ? "DA" : "NE");
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |