Submission #579049

#TimeUsernameProblemLanguageResultExecution timeMemory
579049Trisanu_DasKamenčići (COCI21_kamencici)C++17
70 / 70
84 ms169596 KiB
#include <bits/stdc++.h> using namespace std; #define N 351 int n, k; string s; int dp[351][351][351], red[351]; void memo(int l, int r, int m){ if(dp[l][r][m] != -1) return; int already_coll = 0; if(l != 0) already_coll = red[n - 1] - m - red[r] + red[l - 1]; else already_coll = red[n - 1] - m - red[r]; if(m >= k){ dp[l][r][m] = 0; return; } if(already_coll >= k){ dp[l][r][m] = 1; return; } if(l == r){ dp[l][r][m] = 0; return; } memo(l + 1, r, already_coll); memo(l, r - 1, already_coll); dp[l][r][m] = (!dp[l + 1][r][already_coll] || !dp[l][r - 1][already_coll]); } int main(){ cin >> n >> k >> s; red[0] = (s[0] == 'C'); memset(dp, -1, sizeof(dp)); for(int i = 1; i < n; i++) red[i] = red[i - 1] + (s[i] == 'C'); memo(0, n - 1, 0); if(dp[0][n - 1][0]) cout << "DA\n"; else cout << "NE\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...