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"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
const int N = 352;
int dp[N][N][N];
int prf[N];
int n, k;
string s;
// A takes cnt,
int solve(int cnt, int l, int r) {
if (dp[cnt][l][r] != -1) return dp[cnt][l][r];
int remains = prf[r] - prf[l - 1];
int Btakes = prf[n] - remains - cnt;
if (cnt >= k) return 0;
else if (Btakes >= k) return 1;
int ans = 0;
if (l + 1 <= r && solve(cnt + (s[l] == 'C'), l + 1, r) == 0)
ans = 1;
if (r - 1 >= l && solve(cnt + (s[r] == 'C'), l, r - 1) == 0)
ans = 1;
return dp[cnt][l][r] = ans;
}
// 1: last position of x, -1: second-last position of x -> sum(l, r) = 0-> non-unique subarray, > 0: unique
signed main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> k;
cin >> s;
s = "@" + s;
for (int i = 1; i <= n; ++i)
prf[i] = prf[i - 1] + (s[i] == 'C');
memset(dp, -1, sizeof dp);
cout << (solve(0, 1, n)? "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... |