이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |