제출 #1128702

#제출 시각아이디문제언어결과실행 시간메모리
1128702jackofall718Kamenčići (COCI21_kamencici)C++20
70 / 70
130 ms171136 KiB
#include <bits/stdc++.h> #define ll long long int #define endl '\n' #define vn vector<ll> using namespace std; const int MAXN = 352; int n, k; char str[MAXN]; int prefix[MAXN]; int dp[MAXN][MAXN][MAXN]; int can_win(int l, int r, int uk) { int &res = dp[l][r][uk]; if (res != -1) return res; int total_red = prefix[n - 1]; int red_left = prefix[r] - (l ? prefix[l - 1] : 0); int other_red = total_red - red_left - uk; if (uk >= k) return res = 0; if (other_red >= k) return res = 1; return res = !can_win(l + 1, r, other_red) || !can_win(l, r - 1, other_red); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 0; i < n; i++) { cin >> str[i]; prefix[i] = (i ? prefix[i - 1] : 0) + (str[i] == 'C'); } memset(dp, -1, sizeof(dp)); if (can_win(0, n - 1, 0)) { cout << "DA" << endl; } else { cout << "NE" << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...