Submission #861743

# Submission time Handle Problem Language Result Execution time Memory
861743 2023-10-16T22:37:21 Z HossamHero7 Kamenčići (COCI21_kamencici) C++14
70 / 70
38 ms 175536 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int n,k;
string s;
int dp[355][355][355];
vector<int> prefix, suffix;

int solve(int l,int r,int cnt){
    bool turn = (l + n-r-1)&1;
    int rem = prefix[l] + suffix[r+1] - cnt;
    if(l>r) return rem == k ? !turn : 0;
    if(cnt==k) return (turn);
    if(rem == k) return !turn;
    int &ret = dp[l][r][cnt];
    if(~ret) return ret;
    bool c1 = solve(l+1,r,cnt+(s[l]=='C'&&!turn));
    bool c2 = solve(l,r-1,cnt+(s[r]=='C'&&!turn));
    return ret = !(c1&c2);
}
void solve(){
    cin>>n>>k;
    cin>>s;
    prefix.resize(n+1), suffix.resize(n+1);
    for(int i=1;i<=n;i++) prefix[i] = (s[i-1] == 'C') + prefix[i-1];
    for(int i=n-1;i>=0;i--) suffix[i] = (s[i] == 'C') + suffix[i+1];
    memset(dp,-1,sizeof(dp));
    cout<<(solve(0,n-1,0)?"DA":"NE")<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 175448 KB Output is correct
2 Correct 19 ms 175452 KB Output is correct
3 Correct 20 ms 175452 KB Output is correct
4 Correct 19 ms 175408 KB Output is correct
5 Correct 21 ms 175336 KB Output is correct
6 Correct 19 ms 175452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 175448 KB Output is correct
2 Correct 19 ms 175452 KB Output is correct
3 Correct 20 ms 175452 KB Output is correct
4 Correct 19 ms 175408 KB Output is correct
5 Correct 21 ms 175336 KB Output is correct
6 Correct 19 ms 175452 KB Output is correct
7 Correct 19 ms 175452 KB Output is correct
8 Correct 19 ms 175320 KB Output is correct
9 Correct 20 ms 175448 KB Output is correct
10 Correct 19 ms 175452 KB Output is correct
11 Correct 19 ms 175536 KB Output is correct
12 Correct 19 ms 175452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 175448 KB Output is correct
2 Correct 19 ms 175452 KB Output is correct
3 Correct 20 ms 175452 KB Output is correct
4 Correct 19 ms 175408 KB Output is correct
5 Correct 21 ms 175336 KB Output is correct
6 Correct 19 ms 175452 KB Output is correct
7 Correct 19 ms 175452 KB Output is correct
8 Correct 19 ms 175320 KB Output is correct
9 Correct 20 ms 175448 KB Output is correct
10 Correct 19 ms 175452 KB Output is correct
11 Correct 19 ms 175536 KB Output is correct
12 Correct 19 ms 175452 KB Output is correct
13 Correct 19 ms 175452 KB Output is correct
14 Correct 38 ms 175448 KB Output is correct
15 Correct 23 ms 175448 KB Output is correct
16 Correct 35 ms 175532 KB Output is correct
17 Correct 29 ms 175448 KB Output is correct
18 Correct 24 ms 175452 KB Output is correct