제출 #1306332

#제출 시각아이디문제언어결과실행 시간메모리
1306332guardianecKamenčići (COCI21_kamencici)C++20
70 / 70
267 ms355648 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; ll n,k; string s; vector<vector<vector<ll>>> memo(355, vector<vector<ll>>(355, vector<ll>(355))); vector<ll> pref(355); ll find(ll l, ll r, ll k1){ if (k1>=k) return 0; if (memo[l][r][k1]!=-1) return memo[l][r][k1]; ll k2 = pref[r+1]-pref[l]; k2 = pref[n]-k2; k2 = k2-k1; if (k2>=k) return memo[l][r][k1] = 1; if (l>r) return memo[l][r][k1] = 1; bool yes1 = 0; if (k1+(s[l]=='C')<k){ if (find(l+1,r,k2)==0) yes1 = 1; } if (yes1) return memo[l][r][k1] = 1; bool yes2 = 0; if (k1+(s[r]=='C')<k){ if (find(l,r-1,k2)==0) yes2 = 1; } if (yes2) return memo[l][r][k1] = 1; return memo[l][r][k1] = 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> s; for (int i=0; i<n; i++){ pref[i+1] = pref[i] + (s[i]=='C'); } for (int i=0; i<355; i++){ for (int j=0; j<355; j++){ memo[i][j].assign(355,-1); } } if (find(0, n-1, 0)) { cout << "DA" << endl; } else { cout << "NE" << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...