이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |