This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() { cout << "\n"; }
template<typename T, typename...U>
void dout(T t, U...u) { cout << t << (sizeof...(u) ? ", " : ""), dout(u...); }
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for(int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 355;
int n, k;
string s;
int pre[SIZE];
int dp[SIZE][SIZE][SIZE];
int cal(int l, int r, int cur) {
if (dp[l][r][cur] != -1) return dp[l][r][cur];
int cnt = pre[n] - (pre[r] - pre[l - 1]) - cur;
if (cur >= k) dp[l][r][cur] = 0;
else if (cnt >= k) dp[l][r][cur] = 1;
else dp[l][r][cur] = (!cal(l, r - 1, cnt) || !cal(l + 1, r, cnt));
return dp[l][r][cur];
}
void solve() {
cin >> n >> k;
cin >> s, s = " " + s;
FOR (i, 1, n) pre[i] = pre[i - 1] + (s[i] == 'C');
FOR (i, 1, n) FOR (j, 1, n) FOR (p, 0, n) dp[i][j][p] = -1;
cout << (cal(1, n, 0) ? "DA" : "NE") << '\n';
}
int main() {
Waimai;
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |