| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1333151 | hauserl | Kamenčići (COCI21_kamencici) | C++20 | 51 ms | 85532 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) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
