Submission #487130

#TimeUsernameProblemLanguageResultExecution timeMemory
487130JovanBKamenčići (COCI21_kamencici)C++17
70 / 70
34 ms22872 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

const int N = 350;

bool dp[N+5][N+5][N+5];
int pre[N+5];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    for(int i=1; i<=n; i++){
        if(s[i-1] == 'C') pre[i]++;
        pre[i] += pre[i-1];
    }
    for(int len=1; len<=n; len++){
        for(int l=1; l+len-1<=n; l++){
            int r = l + len - 1;
            int svi = pre[n] - pre[r] + pre[l-1];
            for(int j=0; j<=svi; j++){
                if(j >= k) continue;
                if(svi - j >= k){
                    dp[l][r][j] = 1;
                    continue;
                }
                if(s[l-1] == 'C' && j+1 < k && !dp[l+1][r][svi - j]) dp[l][r][j] = 1;
                if(s[l-1] == 'P' && !dp[l+1][r][svi - j]) dp[l][r][j] = 1;
                if(s[r-1] == 'C' && j+1 < k && !dp[l][r-1][svi - j]) dp[l][r][j] = 1;
                if(s[r-1] == 'P' && !dp[l][r-1][svi - j]) dp[l][r][j] = 1;
            }
        }
    }
    if(dp[1][n][0]) cout << "DA\n";
    else cout << "NE\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...