CSES - Datatähti 2022 loppu - Results
Submission details
Task:Peli
Sender:MojoLake
Submission time:2023-01-18 18:47:39 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.42 s1, 2, 3details
#20.67 s2, 3details
#3--3details
#4ACCEPTED0.39 s1, 2, 3details
#5ACCEPTED0.40 s1, 2, 3details

Code

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;
const int K = 10;

int dp[N+1][K+1][K+1][K+1];
// dp[i][A][B][C}]


int main(){

    memset(dp, -1, sizeof(dp));
    for(int i = 0; i <= N; ++i){
        dp[i][0][0][0] = 0;
    }

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s = "#" + s;

    for(int i = 1; i <= n; ++i){
        int x = (s[i] == 'B') + 2 * (s[i] == 'C');

        for(int a = 0; a <= k; ++a){
            for(int b = 0; b <= k; ++b){
                for(int c = 0; c <= k; ++c){
                    if(dp[i-1][a][b][c] == -1)continue;
                    if(a+b+c>k-1)continue;

                    // cout << dp[i-1][a][b][c] << "\n";

                    if(x == 0){
                        // A 
                        if(b&&c){
                            dp[i][a][b-1][c-1] = dp[i-1][a][b][c] + 1;
                        }
                        else dp[i][a+1][b][c] = dp[i-1][a][b][c];
                    }

                    if(x == 1){
                        // B
                        if(a&&c){
                            dp[i][a-1][b][c-1] = dp[i-1][a][b][c] + 1;
                        }
                        else dp[i][a][b+1][c] = dp[i-1][a][b][c];
                    }

                    if(x == 2){
                        // C
                        if(a&&b){
                            dp[i][a-1][b-1][c] = dp[i-1][a][b][c] + 1;
                        }
                        else dp[i][a][b][c+1] = dp[i-1][a][b][c];
                    }
    

                }
            }
        }
    }

    int ans = 0;

    for(int a = 0; a <= k; ++a)
        for(int b = 0; b <= k; ++b)
            for(int c = 0; c <= k; ++c)
                if(a+b+c<=k)ans = max(ans, dp[n][a][b][c]);


    cout << ans << "\n";

    
    



    



}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
100000 3
BBAACBCBACBACABBCBAABCBCCBCCAA...

correct output
18201

user output
0

Test 2

Group: 2, 3

Verdict:

input
100000 10
BAACABCCBCBAACBBCCCCABBBBACCBA...

correct output
29684

user output
44

Test 3

Group: 3

Verdict:

input
100000 50
ACAABCBBAAAACCBBABACACACBCAACA...

correct output
32740

user output
(empty)

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
3 1
ABC

correct output
0

user output
0

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
3 2
ABC

correct output
0

user output
0