이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |