Submission #675506

#TimeUsernameProblemLanguageResultExecution timeMemory
675506TangirkulKamenčići (COCI21_kamencici)C++17
30 / 70
1 ms1364 KiB
#include<bits/stdc++.h> #define ll long long #define fi first #define se second #define pb push_back #define sz size #define Junanna ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll K = 32; const ll INF = 1e9 + 7; const ll MOD = 1e9 + 7; const ll N = (1e5 + 125); ll n, k; string s; ll dp[400][400], p[500]; ll rec (ll l, ll r, ll a, ll b) { if (dp[l][r] != -1) { return dp[l][r]; } if (b == k) { return 1; } if (a == k) { return 0; } if (l == r) { if (n % 2 == 0) { return 1; } else { if ((s[l] == 'C' && a < k) || s[l] == 'P') { return 1; } else { return 0; } } } if ((n - (r - l + 1)) % 2 == 1) { dp[l][r] = min (rec (l + 1, r, a, b + (s[l] == 'C')), rec (l, r - 1, a, b + (s[r] == 'C'))); return dp[l][r]; } else { dp[l][r] = max (rec (l + 1, r, a + (s[l] == 'C'), b), rec (l, r - 1, a + (s[r] == 'C'), b)); return dp[l][r]; } } void ma1n () { cin >> n >> k; cin >> s; for (ll i = 0; i <= n; i++) { for (ll j = 0; j <= n; j++) { dp[i][j] = -1; } } for (ll i = 0; i < n; i++) { p[i] = p[i - 1] + (s[i] == 'C'); } if (rec (0, n - 1, 0, 0)) { cout << "DA"; } else { cout << "NE"; } } int main () { Junanna; ll t = 1; while (t--) { ma1n (); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...