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;
using ll = long long;
using ld = long double;
const int N = 350;
bool dp[N+5][N+5][N+5];
int pre[N+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, k;
cin >> n >> k;
string s;
cin >> s;
for(int i=1; i<=n; i++){
if(s[i-1] == 'C') pre[i]++;
pre[i] += pre[i-1];
}
for(int len=1; len<=n; len++){
for(int l=1; l+len-1<=n; l++){
int r = l + len - 1;
int svi = pre[n] - pre[r] + pre[l-1];
for(int j=0; j<=svi; j++){
if(j >= k) continue;
if(svi - j >= k){
dp[l][r][j] = 1;
continue;
}
if(s[l-1] == 'C' && j+1 < k && !dp[l+1][r][svi - j]) dp[l][r][j] = 1;
if(s[l-1] == 'P' && !dp[l+1][r][svi - j]) dp[l][r][j] = 1;
if(s[r-1] == 'C' && j+1 < k && !dp[l][r-1][svi - j]) dp[l][r][j] = 1;
if(s[r-1] == 'P' && !dp[l][r-1][svi - j]) dp[l][r][j] = 1;
}
}
}
if(dp[1][n][0]) cout << "DA\n";
else cout << "NE\n";
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... |