제출 #1333980

#제출 시각아이디문제언어결과실행 시간메모리
1333980reverberatedevKamenčići (COCI21_kamencici)C++20
70 / 70
207 ms350660 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define DEBUG 1

#ifdef DEBUG
    #define OUT(x) cerr << (#x) << '=' << (x) << endl
    #define OUT2(c) cerr << (#c) << " = {"; for (auto it = (c).begin(); it != (c).end(); ++it) cerr << (it == (c).begin() ? "" : ", ") << *it; cerr << "}" << endl;
#else
    #define OUT(x)
    #define OUT2(c)
#endif

const int MAXN = 355;
const int INF = 1e18;

int memo[MAXN][MAXN][MAXN];
int n, k;
string s;
int peb[MAXN], pre[MAXN], suf[MAXN];

int dp(int l, int r, int me){ // True current player can win such that they have made their move, have me reds and [l, r] is available
    int him = pre[l - 1] + suf[r + 1] - me;
    if(me >= k) return 0LL;
    if(him >= k) return 1LL;

    if(memo[l][r][me] != -1) return memo[l][r][me];

    bool res = 0;
    // opp takes l
    res = !dp(l + 1, r, him + peb[l]) & !dp(l, r - 1, him + peb[r]);

    return memo[l][r][me] = res;
}

void solve() {
    cin >> n >> k;
    cin >> s;
    memset(memo, -1, sizeof(memo));
    // Precomputation
    for(int i = 0; i < n; i++){
        peb[i + 1] = s[i] == 'C';
    }
    for(int i = 1; i <= n; i++){
        pre[i] = peb[i] + pre[i - 1];
    }
    for(int i = n; i >= 1; i--){
        suf[i] = peb[i] + suf[i + 1];
    }
    cout << (dp(1, n, 0) ? "NE" : "DA");
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int tt; tt = 1;
    while (tt--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...