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>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const int N=355;
int n,k,dp[N][N][N],pre[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
memset(dp, -1, sizeof dp);
cin>>n>>k;
string str;
cin>>str;
str=str;
for(int i=1;i<=n;i++)pre[i]=pre[i-1]+(str[i-1]=='C');
for(int l=n;l>=1;l--){
for(int r=l;r<=n;r++){
for(int cnt=0;cnt<=n;cnt++){
if(cnt>=k){
dp[l][r][cnt]=0;
continue;
}
int cnt2=pre[n]-cnt-(pre[r]-pre[l-1]);
if(cnt2>=k)dp[l][r][cnt]=1;
else dp[l][r][cnt]=(!dp[l+1][r][cnt2])||(!dp[l][r-1][cnt2]);
}
}
}
cout<<(dp[1][n][0]?"DA\n":"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... |