제출 #1333151

#제출 시각아이디문제언어결과실행 시간메모리
1333151hauserlKamenčići (COCI21_kamencici)C++20
70 / 70
51 ms85532 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int k;
int n;
string pebbles;
vector<int> pref;
int gesC;

vector<vector<vector<int>>> dp;


bool f2(int l, int r, int currK) {
    int opK = gesC - (pref[r] - pref[l]) - currK;

    if (currK >= k) return false;
    if (opK >= k) return true;

    if (dp[l][r][currK] != -1) return dp[l][r][currK];

    bool myTurn = (n - (r-l)) % 2 == 0;

    int res;
    if (myTurn) {
        res = false;
        res |= f2(l+1, r, currK+(pebbles[l]=='C'));
        res |= f2(l, r-1, currK+(pebbles[r-1]=='C'));
    } else {
        res = true;
        res &= f2(l+1, r, currK);
        res &= f2(l, r-1, currK);
    }

    dp[l][r][currK] = res;
    return res;
}

int main() {
    
    scanf("%d %d", &n, &k);

    cin >> pebbles;

    gesC = 0;
    pref.resize(n+1, 0); 
    for (int i = 0; i < n; i++) {
        pref[i+1] = pref[i] + (pebbles[i] == 'C');
        gesC += (pebbles[i] == 'C');
    }

    dp.resize(n+1, vector<vector<int>>(n+1, vector<int>(k+1, -1)));

    f2(0,n,0);
    bool res = dp[0][n][0];

    if (res) {
        cout << "DA";
    } else {
        cout << "NE";
    }

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...