#include <bits/stdc++.h>
/*
Checklist:
- Check statement:
- Check filename:
- Check test limit:
- Stresstest:
*/
using namespace std;
using ll = long long;
// #define int long long
#define pii pair<ll, ll>
#define fi first
#define se second
const ll N = 350 + 5, inf = 1e9, mod = 1e9 + 7, block = 320, lim = 19;
int n, k;
string s;
int total;
int pfs[N];
int f[N][N][N];
int dp(int l, int r, int nowA) { // xet den doan [l, r], now la co bao nhieu mau do ma A da lay
if (nowA >= k) return 0;
if (l > r) return 1;
if (f[l][r][nowA] != -1) return f[l][r][nowA];
int have = total - (pfs[r] - pfs[l - 1]);
int nowB = have - nowA; // so mau do ma B da lay
int nowturn = (l - 1) + (n - r);
if (nowturn % 2 == 0) { // An
int Win = 0;
if (nowA + (s[l] == 'C') < k) {
if (dp(l + 1, r, nowA + (s[l] == 'C'))) Win = 1;
}
if (Win == 0) {
if (nowA + (s[r] == 'C') < k) {
if (dp(l, r - 1, nowA + (s[r] == 'C'))) Win = 1;
}
}
return f[l][r][nowA] = Win;
}
else {
int Lose = 0;
if (nowB + (s[l] == 'C') < k) {
if (!dp(l + 1, r, nowA)) {
return f[l][r][nowA] = 0;
}
}
if (nowB + (s[r] == 'C') < k) {
if (!dp(l, r - 1, nowA)) {
return f[l][r][nowA] = 0;
}
}
}
return f[l][r][nowA] = 1;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
if (fopen("SGAME.inp", "r")) {
freopen("SGAME.inp", "r", stdin);
freopen("SGAME.out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc-- > 0) {
cin >> n >> k;
cin >> s;
s = "#" + s;
memset(f, -1, sizeof(f));
total = 0;
for (int i = 1; i <= n; i++) {
total += (s[i] == 'C');
pfs[i] = pfs[i - 1] + (s[i] == 'C');
}
int ans = dp(1, n, 0);
cout << (ans ? "DA" : "NE") << '\n';
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen("SGAME.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen("SGAME.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... |