This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()
using namespace std;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 350 + 5;
const int oo = 1e9 + 1;
const int mod = 1e9 + 7;
//const ll oo = 5e18;
int n, k, dp[N][N][N], p[N];
string s;
int solve(int l, int r, int K) {
if(dp[l][r][K] != -1) return dp[l][r][K];
if(K >= k) return dp[l][r][K] = 0;
if(p[n] - p[r] + p[l - 1] - K >= k) return dp[l][r][K] = 1;
if ((n - (r - l + 1)) % 2) return dp[l][r][K] = (solve(l + 1, r, K) & solve(l, r - 1, K));
return dp[l][r][K] = (solve(l + 1, r, K + (s[l] == 'C')) | solve(l, r - 1, K + (s[r] == 'C')));
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
memset(dp, -1, sizeof(dp));
cin >> n >> k >> s;
s = " " + s;
for (int i = 1; i <= n; i++) p[i] = p[i - 1] + (s[i] == 'C');
cout << (solve(1, n, 0) ? "DA" : "NE") << "\n";
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen(task ".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen(task ".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |