제출 #874570

#제출 시각아이디문제언어결과실행 시간메모리
874570ngjabachKamenčići (COCI21_kamencici)C++14
70 / 70
55 ms175476 KiB
// NgJaBach: Forever Meadow <3

#include<bits/stdc++.h>

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef unsigned long long ull;
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define bend(a) a.begin(),a.end()
#define rev(x) reverse(bend(x))
#define mset(a) memset(a, 0, sizeof(a))
#define fi first
#define se second
#define gcd __gcd
#define getl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
#define endl '\n'
const int N=355,M=1000000007;
const ll INF=1e18+7;
int dp[N][N][N],pref[N],n,k;
string s;
int can_win(int L,int R,int reds){
    int &res=dp[L][R][reds];
//    cout<<L<<" "<<R<<" "<<reds<<endl;
    if(res==-1){
        int other_reds=pref[n]-pref[R]+pref[L-1]-reds;
        if(reds>=k) res=0;
        else if(other_reds>=k) res=1;
        else{
            if(!can_win(L+1,R,other_reds) or !can_win(L,R-1,other_reds)) res=1;
            else res=0;
        }
    }
        
    return res;
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
//    freopen(".inp","r",stdin);
//    freopen(".out","w",stdout);
    cin>>n>>k;
    cin>>s; s="$"+s;
    pref[0]=0;
    for(int i=1;i<=n;++i) pref[i]=pref[i-1]+(s[i]=='C');
    for(int i=0;i<N;++i) for(int j=0;j<N;++j) for(int d=0;d<N;++d) dp[i][j][d]=-1;
    if(can_win(1,n,0)) cout<<"DA";
    else cout<<"NE";
    return 0;
}
/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...