제출 #673102

#제출 시각아이디문제언어결과실행 시간메모리
673102HalfKamenčići (COCI21_kamencici)C++17
70 / 70
43 ms20428 KiB

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"WAFFLES "<<i<<"<\n"
#define INF 1000000000000000000LL
#define EPS (0.00000000001L)
#define pi (3.141592653589793L)
#define VV(vvvv,NNNN,xxxx); REP(iiiii,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007LL;

template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}

template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} 

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cout.precision(20);

    ll k, n;
    cin >> n >> k;
    bool dp[k+1][n][n];
   	string row;
   	cin >> row;
   	ll cs[n+1];
   	cs[0] = 0;
   	for(ll i = 0; i < n; ++i){
   		cs[i+1] = cs[i] + (row[i] == 'C');
   	}
   	ll totc = cs[n];
   	for(ll i = 0; i < n; ++i)for(ll j = 0; j < n; ++j){
		dp[k][i][j] = false;
	}
   	for(ll l = 0; l < n; ++l){
   		for(ll i = 0; i+l < n; ++i){
   			for(ll ki = 0; ki < k; ++ki){
   				ll otk = totc-(cs[i+l+1]-cs[i])-ki;
   				if(otk >= k){
   					dp[ki][i][i+l] = true;
   				}else{
   					if(!dp[otk][i+1][i+l] || !dp[otk][i][i+l-1]){
   						dp[ki][i][i+l] = true;
   					}else{
   						dp[ki][i][i+l] = false;
   					}
   				}
   			}
   		}
   	}
   	cout << (dp[0][0][n-1]?"DA\n":"NE\n");


	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...