Submission #494391

# Submission time Handle Problem Language Result Execution time Memory
494391 2021-12-15T11:35:34 Z AlperenT Kamenčići (COCI21_kamencici) C++17
70 / 70
22 ms 22860 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 350 + 5;

int n, k, prefix[N], sum;

string str;

bool dp[N][N][N];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n >> k;

    cin >> str;

    str = '$' + str;

    for(int i = 1; i <= n; i++) prefix[i] = prefix[i - 1] + (str[i] == 'C');

    for(int l = n; l >= 1; l--){
        for(int r = l; r <= n; r++){
            sum = prefix[n] - (prefix[r] - prefix[l - 1]);

            for(int i = 0; i < k; i++){
                int j = sum - i;

                if(j >= k) dp[l][r][i] = true;
                else{
                    if(!dp[l + 1][r][j] || !dp[l][r - 1][j]) dp[l][r][i] = true;
                    else dp[l][r][i] = false;
                }
            }
        }
    }

    cout << (dp[1][n][0] ? "DA" : "NE");
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 832 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 1 ms 844 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 448 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 844 KB Output is correct
8 Correct 1 ms 832 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 1 ms 844 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
13 Correct 12 ms 22860 KB Output is correct
14 Correct 16 ms 22732 KB Output is correct
15 Correct 10 ms 20684 KB Output is correct
16 Correct 17 ms 22620 KB Output is correct
17 Correct 22 ms 22732 KB Output is correct
18 Correct 16 ms 22604 KB Output is correct