#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<x, null_type,
ll mod=(ll)1e9+7;
ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
int dp[352][352][350][2];
vi arr;
int prf[350];
string s;
int k;
int n;
int ans(int l,int r,int red,int turn)
{
int red1=prf[n-1]-prf[r];
red1+=(l?prf[l-1]:0);
red1-=red;
if((turn&&red==k)||(!turn&&red1==k))
return turn;
if(dp[l][r][red][turn]!=-1)return dp[l][r][red][turn];
int e;
if(turn)
{
e=ans(l+1,r,red,turn^1);
e=max(ans(l,r-1,red,turn^1),e);
}
else
{
e=ans(l+1,r,red+(s[l]=='C'),turn^1);
e=min(e,ans(l,r-1,red+(s[r]=='C'),turn^1));
}
return dp[l][r][red][turn]=e;
}
void preprocess() {}
void solve()
{
memset(dp,-1,sizeof dp);
cin>>n>>k;
cin>>s;
prf[0]=s[0]=='C';
for(int i=1;i<n;i++)
prf[i]=prf[i-1]+(s[i]=='C');
if(ans(0,n-1,0,0)!=0)cout<<"NE"<<endl;
else cout<<"DA"<<endl;
}
signed main()
{
// freopen("meta_game_input.txt","r",stdin);
// freopen("otput.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
preprocess();
int t=1,st;
//cin>>t;
while(t--)
solve();
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:65:13: warning: unused variable 'st' [-Wunused-variable]
65 | int t=1,st;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
274 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
274 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
274 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |