#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int MAXN = 355;
int N, K, pre[MAXN], suf[MAXN];
bitset <MAXN/2> dp[MAXN][MAXN];
string S;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> K >> S;
S = "."+S;
for (int i=1;i<=N;i++) {
pre[i] = pre[i-1] + (S[i]=='C');
}
for (int i=N;i>=1;i--) {
suf[i] = suf[i+1] + (S[i]=='C');
}
for (int L=N;L>=1;L--) {
for (int R=L-1;R<=N;R++) {
for (int A=0;A<=K;A++) {
if (A == K) {
dp[L][R][A] = 0;
continue;
}
if (pre[L-1] + suf[R+1] - A >= K) {
dp[L][R][A] = 1;
continue;
}
if ((R-L)%2 == (N-1)%2) {
dp[L][R][A] = dp[L+1][R][A+(S[L]=='C')] || dp[L][R-1][A+(S[R]=='C')];
}
else {
dp[L][R][A] = dp[L+1][R][A] && dp[L][R-1][A];
}
}
}
}
if (dp[1][N][0]) {
cout << "DA\n";
}
else {
cout << "NE\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... |