This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DEBUG false
using namespace std;
const int MAX_N = 1e5 + 10;
char S[MAX_N];
int A[MAX_N];
int dp[2][4][4][4][4];
int cal(const int &x, const int &y, const int &z) {
int res = 0;
for(int i = 1; i <= 3; i++) {
if(x == i or y == i or z == i) {
res++;
}
}
return res;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N >> (S + 1);
for(int i = 1; i <= N; i++) {
if(S[i] == 'M') {
A[i] = 1;
}
else if(S[i] == 'B') {
A[i] = 2;
}
else if(S[i] == 'F') {
A[i] = 3;
}
}
for(int i = N; i >= 1; i--) {
for(int i1 = 0; i1 <= 3; i1++) {
for(int i2 = 0; i2 <= 3; i2++) {
for(int j1 = 0; j1 <= 3; j1++) {
for(int j2 = 0; j2 <= 3; j2++) {
dp[1][i1][i2][j1][j2] = max(dp[0][A[i]][i1][j1][j2] + cal(A[i], i1, i2),
dp[0][i1][i2][A[i]][j1] + cal(A[i], j1, j2));
}
}
}
}
for(int i1 = 0; i1 <= 3; i1++) {
for(int i2 = 0; i2 <= 3; i2++) {
for(int j1 = 0; j1 <= 3; j1++) {
for(int j2 = 0; j2 <= 3; j2++) {
dp[0][i1][i2][j1][j2] = dp[1][i1][i2][j1][j2];
}
}
}
}
}
cout << dp[0][0][0][0][0];
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |