Submission #1329925

#TimeUsernameProblemLanguageResultExecution timeMemory
1329925secondaccountmaybeKamenčići (COCI21_kamencici)C++20
70 / 70
163 ms341804 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int m=352;
ll n,k,p[m],d[m][m][m];
string s;
ll f(ll l,ll r,ll u)
{
	ll&v=d[l][r][u];
	if(v==-1)
	{
		ll t=p[n-1];
		ll x=p[r]-(l?p[l-1]:0);
		ll o=t-x-u;
		if(u>=k)
		{
			v=0;
		}
		else if(o>=k)
		{
			v=1;
		}
		else
		{
			if(!f(l+1,r,o)||!f(l,r-1,o))
			{
				v=1;
			}
			else
			{
				v=0;
			}
		}
	}
	return v;
}
int main()
{
	memset(d,-1,sizeof(d));
	cin>>n>>k>>s;
	p[0]=(s[0]=='C');
	for(ll i=1;i<n;i++)
	{
		p[i]=p[i-1]+(s[i]=='C');
	}
	if(f(0,n-1,0))
	{
		cout<<"DA"<<endl;
	}
	else
	{
		cout<<"NE"<<endl;
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...