#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define ve vector
#define all(x) x.begin(), x.end()
#define fo(i,a,b) for (int i=(a); i<=(b); ++i)
#define fd(i,a,b) for (int i=(a); i>=(b); --i)
#define maxi(a, b) a = max(a, b)
#define mini(a, b) a = min(a, b)
#define siz(x) ((int)(x).size())
#define vi ve<int>
#define _ << ' ' <<
const int N = 355, inf = 1e9+10, mod = 1e9+7;
bool MBE;
/**
**/
int n, k, a[N], pre[N], suf[N], dp[N][N][N];
/// 2 dau i, j, va A da co k vien da do
int f(int l, int r, int x, int turn) {
int y = pre[l-1]+suf[r+1]-x;
if (x >= k) {
return (turn == 1);
}
if (y >= k) {
return (turn == 0);
}
int &ans = dp[l][r][x];
if (ans != -1) return ans;
ans = 0;
int nxl = (turn == 0 ? x+a[l] : x);
int nxr = (turn == 0 ? x+a[r] : x);
if (f(l+1, r, nxl, turn^1) == 0)
ans = 1;
if (f(l, r-1, nxr, turn^1) == 0)
ans = 1;
return ans;
}
void sol() {
cin >> n >> k;
fo(i,1,n) {
char c; cin >> c;
a[i] = (c == 'C');
}
fo(i,1,n) {
pre[i]=pre[i-1]+a[i];
}
fd(i,n,1) {
suf[i]=suf[i+1]+a[i];
}
memset(dp,-1,sizeof(dp));
int ans = f(1, n, 0, 0);
cout << (ans == 1 ? "DA" : "NE");
}
bool MED;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
if(fopen("A.inp","r")) {
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
}
int tc = 1; // cin >> tc;
fo(i,1,tc) sol();
// cerr << "Memory = " << abs(&MED - &MBE)/1024.0/1024.0 << " MB";
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen("A.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen("A.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |