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>
using namespace std;
#define ll long long
int n, k;
string s;
vector<int> v;
vector<vector<vector<int>>> dp(350, vector<vector<int>>(350, vector<int>(350, -1)));
int f(int i, int j, int x, int als){
if (x >= k){
return 0;
}
else if (als >= k){
dp[i][j][x] = 1;
}
else if (dp[i][j][x] != -1){
return dp[i][j][x];
}
else if (i == j){
if (s[i] == 'C'){
x++;
}
if (x < k){
dp[i][j][x] = 1;
}
else{
dp[i][j][x] = 0;
}
}
else if (i == j - 1){
int x1 = x + v[i];
int x2 = x + v[j];
if (x1 < k || x2 < k){
dp[i][j][x] = 1;
}
else{
dp[i][j][x] = 0;
}
}
else{
dp[i][j][x] = max(min(f(i + 1, j - 1, x + v[i], als + v[j]), f(i + 2, j, x + v[i], als + v[i + 1])),
min(f(i + 1, j - 1, x + v[j], als + v[i]), f(i, j - 2, x + v[j], als + v[j - 1])));
}
return dp[i][j][x];
}
int main(){
cin>>n>>k;
cin>>s;
for (int i = 0; i < n; i++){
if (s[i] == 'C'){
v.push_back(1);
}
else{
v.push_back(0);
}
}
int ans = f(0, n - 1, 0, 0);
if (ans == 1){
cout<<"DA";
}
else{
cout<<"NE";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |