Submission #548100

#TimeUsernameProblemLanguageResultExecution timeMemory
548100aryan12Kamenčići (COCI21_kamencici)C++17
70 / 70
153 ms338840 KiB
#include <bits/stdc++.h> using namespace std; #define int long long mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); int n, k; string s; const int N = 351; int dp[N][N][N]; int pref[N]; void recur(int l, int r, int num_pebbles) { if(dp[l][r][num_pebbles] != -1) { return; } int opp_pebbles = 0; if(l != 0) opp_pebbles = pref[n - 1] - num_pebbles - pref[r] + pref[l - 1]; else opp_pebbles = pref[n - 1] - num_pebbles - pref[r]; if(num_pebbles >= k) { dp[l][r][num_pebbles] = 0; return; } if(opp_pebbles >= k) { dp[l][r][num_pebbles] = 1; return; } if(l == r) { dp[l][r][num_pebbles] = 0; return; } recur(l + 1, r, opp_pebbles); recur(l, r - 1, opp_pebbles); if(dp[l + 1][r][opp_pebbles] == 0 || dp[l][r - 1][opp_pebbles] == 0) { dp[l][r][num_pebbles] = 1; return; } dp[l][r][num_pebbles] = 0; return; } void Solve() { cin >> n >> k >> s; pref[0] = (s[0] == 'C'); for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { for(int l = 0; l < N; l++) { dp[i][j][l] = -1; } } } for(int i = 1; i < n; i++) { pref[i] = pref[i - 1] + (s[i] == 'C'); } recur(0, n - 1, 0); if(dp[0][n - 1][0] == 1) { cout << "DA\n"; } else { cout << "NE\n"; } } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...