//*** Bismillah ***//
// It's the evening of another day. And the end of mine...
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#if !defined(ONLINE_JUDGE) and !defined(EVAL)
#include "template/debug.h"
#else
#define d(x...)
#endif
#define ll long long
const ll INF = 1e9;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;
const ll maxn = 350 + 5;
ll n,m,k=0;
ll dp[maxn][maxn][2], a[maxn];
// c = 0 -> A
// c = 1 -> B
// dp[l][r][c] -> [l, r] araliginda round c de olanda A ucun cost
ll f(ll l, ll r, ll c, ll ct){
if(l > r or l > n or r < 1) return 0;
if(dp[l][r][c] != INF) return dp[l][r][c];
if((a[l] and !a[r])){
return f(l, r-1, c^1, ct);
}
if((!a[l] and a[r])){
return f(l+1, r, c^1, ct);
}
if(c == 0){
ll l1 = f(l+1, r, c^1, ct) + 1;
ll l2 = f(l, r-1, c^1, ct) + 1;
return dp[l][r][c] = min(l1, l2);
}
else{
if(ct + 1 >= m) return dp[l][r][c] = 0;
ll l1 = f(l+1, r, c^1, ct + 1);
ll l2 = f(l, r-1, c^1, ct + 1);
return dp[l][r][c] = min(l1, l2);
}
}
void _(){
cin>>n>>m;
char c;
for(ll i=1;i<=n;i++) cin>>c, a[i] = (c == 'C');
for(ll i=1;i<maxn;i++) for(ll j=1;j<maxn;j++) dp[i][j][0] = dp[i][j][1] = INF;
// memset(dp, INF, sizeof(dp));
// cout<<f(1, n, 0)<<'\n';
if(f(1, n, 0, 0) < m) cout<<"DA\n";
else cout<<"NE\n";
}
signed main(){
auto testcaseruntime=clock();
cin.tie(0)->sync_with_stdio(0);
ll t=1;
// cin>>t;
while(t--){
_();
}
cerr<<"\n\033[1;31mTime: \033[1;30m"
<<(double)(clock()-testcaseruntime)/1000000<<"\033[1;32m seconds\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... |