# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
717355 | TheSahib | Kamenčići (COCI21_kamencici) | C++17 | 75 ms | 169568 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define oo 1e9
#define pii pair<int, int>
using namespace std;
const int MAX = 351;
int n, k;
string s;
int reds[MAX];
int dp[MAX][MAX][MAX];
bool f(int l, int r, int red){
if(dp[l][r][red] != -1) return dp[l][r][red];
if(red >= k) return 0;
int red1 = reds[n] - (reds[r] - reds[l - 1]) - red;
if(red1 >= k) return 1;
if(l == r) return 0;
if(f(l + 2, r, red + (s[l] == 'C')) && f(l + 1, r - 1, red + (s[l] == 'C'))) return dp[l][r][red] = 1;
if(f(l, r - 2, red + (s[r] == 'C')) && f(l + 1, r - 1, red + (s[r] == 'C'))) return dp[l][r][red] = 1;
return dp[l][r][red] = 0;
}
void solve(){
memset(dp, -1, sizeof(dp));
cin >> n >> k;
cin >> s;
s.insert(s.begin(), ' ');
for (int i = 1; i <= n; i++)
{
reds[i] = reds[i - 1] + (s[i] == 'C');
}
if(f(1, n, 0)){
cout << "DA\n";
}
else{
cout << "NE\n";
}
}
int main()
{
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |