Submission #731014

# Submission time Handle Problem Language Result Execution time Memory
731014 2023-04-26T19:22:11 Z murad_2005 Kamenčići (COCI21_kamencici) C++14
0 / 70
65 ms 168100 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define piii pair<int, pii>
#define pllll pair<ll, ll>
#define plli pair<ll, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define size(v) v.size()
#define INF 2e9
#define f first
#define s second
#define ln "\n"

using namespace std;

const int up = 350;

string s;

int n, k;
int dp[up][up][up], preff[up];

int win(int l, int r, int red){
    int ok = dp[l][r][k];
    if(ok == -1){
        int total_red = preff[n - 1];
        int red_left = preff[r];
        if(l) red_left -= preff[l - 1];
        int other_red = total_red - red_left - red;
        if(other_red >= k){
            ok = 1;
        }else if(red >= k){
            ok = 0;
        }else{
            if(!win(l + 1, r, other_red) || !win(l, r - 1, other_red)){
                ok = 1;
            }else{
                ok = 0;
            }
        }
        dp[l][r][k] = ok;
    }
    return ok;
}

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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 63 ms 168100 KB Output is correct
2 Incorrect 65 ms 168012 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 168100 KB Output is correct
2 Incorrect 65 ms 168012 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 168100 KB Output is correct
2 Incorrect 65 ms 168012 KB Output isn't correct
3 Halted 0 ms 0 KB -