Submission #497124

#TimeUsernameProblemLanguageResultExecution timeMemory
497124Abrar_Al_SamitKamenčići (COCI21_kamencici)C++17
70 / 70
88 ms85260 KiB
#include<bits/stdc++.h> using namespace std; const int MX = 355; int n, k; string s; int pre[MX], suf[MX]; int getRed(int l, int r) { return pre[l-1] + suf[r+1]; } bool vis[MX][MX][MX][2], dp[MX][MX][MX][2]; bool solve(int l, int r, int red, int who) { bool &ret = dp[l][r][red][who]; if(vis[l][r][red][who]) return ret; vis[l][r][red][who] = 1; int oppred = getRed(l, r)-red; if(s[l]!='C' || red+1<k) ret |= solve(l+1, r, oppred, who^1)==0; if(s[r]!='C' || red+1<k) ret |= solve(l, r-1, oppred, who^1)==0; return ret; } void PlayGround() { cin >> n >> k; cin >> s; s = "#" + s; for(int i=1; i<=n; ++i) { pre[i] = pre[i-1] + (s[i]=='C'); } for(int i=n; i; --i) { suf[i] = suf[i+1] + (s[i]=='C'); } if(solve(1, n, 0, 1)) cout << "DA\n"; else cout << "NE\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...