답안 #899662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899662 2024-01-06T20:16:33 Z Karoot Kamenčići (COCI21_kamencici) C++17
0 / 70
49 ms 71368 KB
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>

#define all(x)  (x).begin(), (x).end()
#define rall(x)  (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;

ll linf = 1e15+1;

inline void scoobydoobydoo(){
    ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

const int MAXN = 501;
int mem[MAXN][MAXN][MAXN][2];
int pref[MAXN];
int n, k;
string s = "";

int dp(int left, int right, int antun, int player){
    if (antun == k) return 0;
    if ((pref[n-1]-pref[right]+(left == 0 ? 0 : pref[left-1])) - antun == k)return 1;
    if (mem[left][right][antun][player] != -1)return mem[left][right][antun][player];
    if (player)mem[left][right][antun][player] = max(dp(left+1, right, antun+(s[left] == 'C'), 0), dp(left, right-1, antun+(s[right] == 'C'), 0));
    else return mem[left][right][antun][player] = min(dp(left+1, right, antun, 1), dp(left, right-1, antun, 1));   
}

int main(){
    scoobydoobydoo();
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        char c; cin >> c;
        s += c;
        pref[i] = (c == 'C');
        if (i != 0)pref[i] += pref[i-1];
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            for (int k = 0; k < n; k++){
                mem[i][j][k][0] = -1;
                mem[i][j][k][1] = -1;
            }
        }
    }
    
    
    if (dp(0, n-1, 0, 1))cout << "DA" << endl;
    else cout << "NE" << endl;

    



    return 0;
}

Compilation message

Main.cpp: In function 'int dp(int, int, int, int)':
Main.cpp:37:102: warning: control reaches end of non-void function [-Wreturn-type]
   37 |     if (player)mem[left][right][antun][player] = max(dp(left+1, right, antun+(s[left] == 'C'), 0), dp(left, right-1, antun+(s[right] == 'C'), 0));
      |                                                                                                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 49 ms 71368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 49 ms 71368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 49 ms 71368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -