이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n, k;
string s;
int dp[352][352][352], pr[352];
bool fun(int l = 0, int r = n - 1, int a = 0)
{
int b = pr[l] + pr[n] - pr[r + 1] - a;
if(dp[l][r][a] != 0)
return dp[l][r][a] - 1;
if(a == k || b == k)
return b == k;
if(!((n - (r - l + 1)) & 1))
{
dp[l][r][a] = 1 + (fun(l + 1, r, a + (s[l] == 'C')) || fun(l, r - 1, a + (s[r] == 'C')));
return dp[l][r][a] - 1;
}
else
{
dp[l][r][a] = 1 + (fun(l + 1, r, a) && fun(l, r - 1, a));
return dp[l][r][a] - 1;
}
}
int main()
{
cin>>n>>k;
cin>>s;
pr[0] = 0;
for(int i = 1; i <= n; i++)
{
pr[i] = pr[i - 1] + (s[i - 1] == 'C');
}
cout<<(fun() ? "DA" : "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... |