Submission #1181059

#TimeUsernameProblemLanguageResultExecution timeMemory
1181059Fikrat_AsadzadehKamenčići (COCI21_kamencici)C++20
0 / 70
0 ms324 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll int
#define FORI(i, n) for(ll i = 0; i < n; i++)
#define FOR(i, n) for(ll i = 1; i <= n; i++)
typedef vector < ll > vl; 
typedef set < ll > setl;
#define ff first
#define ss second    
#define all(v) v.begin(), v.end() 
#define pll pair<ll, ll> 
#define db double
#define nll cout << "\n"
#define nl "\n"
#define sync ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll poww(ll a, ll b){
    ll res = 1;
    while(b){
        if(b & 1)res *= a;
        a *= a;
        b >>= 1;
    }
    return res;
}
const ll mod =  998244353;
const int sz = 350 + 23 ;
const long long imax = LLONG_MAX;
ll n, m, k, res, q, x, y;
ll a[sz];
string s;
ll dp[sz][sz];
ll f(ll l, ll r, ll c1 = 0, ll c2 = 0, ll turn = 1){
    if(l > r || c1 == k)return 0;
    if(c2 == k)return 1;
    if(~dp[l][r])return dp[l][r];
    ll cse = 0;
    if(turn){
        turn = !turn;
        ll x1 = f(l + 1, r, c1 + (s[l] == 'C'), c2, turn);
        ll x2 = f(l, r - 1, c1 + (s[r] == 'C'), c2, turn);
        if(x1 || x2)cse = 1;

    }
    else{
        turn = !turn;
        ll x1 = f(l + 1, r, c1, c2 + (s[l] == 'C'), turn);
        ll x2 = f(l, r - 1, c1, c2 + (s[r] == 'C'), turn);
        if(!x1 || !x2)cse = 0;
        else cse = 1;
    }
    return dp[l][r] = cse;
}   
void solve(){
    cin >> n >> k;
    FOR(i, n){
        FOR(j, n)dp[i][j] = -1;
    }
    cin >> s;
    s = ' ' + s;
    x = f(1, n);
    cout << (x ? "DA" : "NE");

}
//IOI rice hub
signed main(){      
    // freopen("input.txt","r",stdin);a
    // freopen("output.txt","w",stdout);
    sync;
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }   
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...