제출 #1339367

#제출 시각아이디문제언어결과실행 시간메모리
1339367mantaggezKamenčići (COCI21_kamencici)C++20
70 / 70
20 ms22396 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx = 355;
const int INF = 1e9;

int n, k;
int qs[nx];
bool dp[nx][nx][nx];
char s[nx];

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> n >> k;
    for(int i=1;i<=n;i++) {
        cin >> s[i];
        qs[i] = qs[i - 1] + (s[i] == 'C');
    }

    for(int len=1;len<=n;len++) {
        for(int l=1;l<=n-len+1;l++) {
            int r = l + len - 1;
            int red = qs[n] - (qs[r] - qs[l - 1]);
            bool antun = (n - len) % 2 == 0;
            for(int c1=0;c1<=min(red, k - 1);c1++) {
                int c2 = red - c1;
                if(c2 >= k) continue;
                int cur = antun ? c1 : c2;
                bool win = false;
                
                int red_l = (s[l] == 'C');
                if(cur + red_l < k) {
                    if(!dp[l + 1][r][antun ? c1 + red_l : c1]) {
                        win = true;
                    }
                }

                if(!win) {
                    int red_r = (s[r] == 'C');
                    if(cur + red_r < k) {
                        if(!dp[l][r - 1][antun ? c1 + red_r : c1]) {
                            win = true;
                        }
                    }
                }

                dp[l][r][c1] = win;
            }
        }
    }
    
    if(dp[1][n][0]) cout << "DA\n";
    else cout << "NE\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...