#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define piii pair<int, pii>
#define pllll pair<ll, ll>
#define plli pair<ll, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define size(v) v.size()
#define INF 2e9
#define f first
#define s second
#define ln "\n"
using namespace std;
const int up = 355;
string s;
int n, k;
int dp[up][up][up], preff[up];
void init(){
for(int i = 0; i < up; ++i){
for(int j = 0; j < up; ++j){
for(int k = 0; k < up; ++k){
dp[i][j][k] = -1;
}
}
}
}
int win(int l, int r, int red){
int ok = dp[l][r][k];
if(ok == -1){
int total_red = preff[n - 1];
int red_left = preff[r];
if(l) red_left -= preff[l - 1];
int other_red = total_red - red_left - red;
if(red >= k){
ok = 0;
}else if(other_red >= k){
ok = 1;
}else{
if(!win(l + 1, r, other_red) || !win(l, r - 1, other_red)){
ok = 1;
}else{
ok = 0;
}
}
dp[l][r][k] = ok;
}
return ok;
}
void solve(){
cin >> n >> k;
cin >> s;
init();
preff[0] = (s[0] == 'C');
for(int i = 1; i < n; ++i){
preff[i] = preff[i - 1] + (s[i] == 'C');
}
cout << (win(0, n - 1, 0) ? "DA" : "NE");
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
175312 KB |
Output is correct |
2 |
Incorrect |
70 ms |
175304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
175312 KB |
Output is correct |
2 |
Incorrect |
70 ms |
175304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
175312 KB |
Output is correct |
2 |
Incorrect |
70 ms |
175304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |