| Task: | Peli |
| Sender: | MojoLake |
| Submission time: | 2023-01-18 18:55:33 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | WRONG ANSWER | 0.43 s | 1, 2, 3 | details |
| #2 | WRONG ANSWER | 0.80 s | 2, 3 | details |
| #3 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #4 | ACCEPTED | 0.39 s | 1, 2, 3 | details |
| #5 | WRONG ANSWER | 0.40 s | 1, 2, 3 | details |
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)continue;
bool eqk = 0;
if(a + b + c == k){
eqk = 1;
}
// 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 {
if(!eqk)dp[i][a+1][b][c] = dp[i-1][a][b][c];
else{
if(b)dp[i][a+1][b-1][c] = dp[i-1][a][b][c];
if(c)dp[i][a+1][b][c-1] = 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{
if(!eqk)dp[i][a][b+1][c] = dp[i-1][a][b][c];
else{
if(a)dp[i][a-1][b+1][c] = dp[i-1][a][b][c];
if(c)dp[i][a][b+1][c-1] = 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{
if(!eqk)dp[i][a][b][c+1] = dp[i-1][a][b][c];
else{
if(a)dp[i][a-1][b][c+1] = dp[i-1][a][b][c];
if(b)dp[i][a][b-1][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: WRONG ANSWER
| input |
|---|
| 100000 3 BBAACBCBACBACABBCBAABCBCCBCCAA... |
| correct output |
|---|
| 18201 |
| user output |
|---|
| 0 |
Test 2
Group: 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 100000 10 BAACABCCBCBAACBBCCCCABBBBACCBA... |
| correct output |
|---|
| 29684 |
| user output |
|---|
| 45 |
Test 3
Group: 3
Verdict: TIME LIMIT EXCEEDED
| 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: WRONG ANSWER
| input |
|---|
| 3 2 ABC |
| correct output |
|---|
| 0 |
| user output |
|---|
| 1 |
