Submission #1108626

#TimeUsernameProblemLanguageResultExecution timeMemory
1108626huantranKamenčići (COCI21_kamencici)C++17
70 / 70
39 ms169688 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int maxn = 351; const int oo = 1e9 + 7; const ll inf = 1e18; int n, k, tol = 0; int pre[maxn], dp[maxn][maxn][maxn]; int recursive(int l, int r, int m) { if (m >= k) { dp[l][r][m] = 0; return 0; } int h = tol - m - (pre[r] - pre[l - 1]); if (h >= k) { dp[l][r][m] = 1; return 1; } if (dp[l][r][m] != -1) return dp[l][r][m]; dp[l][r][m] = (!recursive(l + 1, r, h) | !recursive(l, r - 1, h)); return dp[l][r][m]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n >> k; string s; cin >> s; s = ' ' + s; for (int i = 1; i <= n; i++) { pre[i] = pre[i - 1] + (s[i] == 'C'); if (s[i] == 'C') tol++; } for (int i = 0; i < maxn; i++) { for (int j = 0; j < maxn; j++) { for (int k = 0; k < maxn; k++) dp[i][j][k] = -1; } } if (recursive(1, n, 0)) cout << "DA"; else cout << "NE"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...