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>
using namespace std;
int n;
vector <int> adds;
int main () {
string s;
cin >> n >> s;
for (auto i : s) {
if (i == 'M') adds.push_back(1);
else if (i == 'F') adds.push_back(2);
else adds.push_back(3);
}
int dp[4][4][4][4][2] = {};
for (int i = n - 1; i >= 0; i--) {
for (int a = 0; a <= 3; a++) {
for (int b = 0; b <= 3; b++) {
for (int c = 0; c <= 3; c++) {
for (int d = 0; d <= 3; d++) {
int cnt = 0;
if (a == 0 && b == 0) {
cnt = 1;
} else if (a && !b) {
cnt = 1 + (a != adds[i]);
} else if (b && !a) {
cnt = 1 + (b != adds[i]);
} else {
if (a == b && a == adds[i]) {
cnt = 1;
} else if (a == b && a != adds[i]) {
cnt = 2;
} else if (b == adds[i] && a != b) {
cnt = 2;
} else if (a == adds[i] && a != b) {
cnt = 2;
} else {
cnt = 3;
}
}
int x = dp[b][adds[i]][c][d][1] + cnt;
if (c == 0 && d == 0) {
cnt = 1;
} else if (c && !d) {
cnt = 1 + (c != adds[i]);
} else if (d && !c) {
cnt = 1 + (d != adds[i]);
} else {
if (c == d && c == adds[i]) {
cnt = 1;
} else if (c == d && c != adds[i]) {
cnt = 2;
} else if (d == adds[i] && c != d) {
cnt = 2;
} else if (c == adds[i] && c != d) {
cnt = 2;
} else {
cnt = 3;
}
}
dp[a][b][c][d][0] = max(x, dp[a][b][d][adds[i]][1] + cnt);
}
}
}
}
for (int a = 0; a <= 3; a++) {
for (int b = 0; b <= 3; b++) {
for (int c = 0; c <= 3; c++) {
for (int d = 0; d <= 3; d++) {
dp[a][b][c][d][1] = dp[a][b][c][d][0];
}
}
}
}
}
cout << dp[0][0][0][0][1] << '\n';
}
# | 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... |