이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
long long n, dp[100010][4][4][4][4], num, maxx;
char ch;
int main() {
cin >> n;
for (int i = 0; i <= n; 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++) dp[i][a][b][c][d] = -1e18;
dp[0][0][0][0][0] = 0;
for (int i = 1; i <= n; i++) {
cin >> ch;
if (ch == 'M') num = 1;
else if (ch == 'B') num = 2;
else num = 3;
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++) {
if ((a == 0) && (b == 0)) dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+1);
else if ((a == 0) && (b == num)) dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+1);
else if ((a == 0) && (b != num)) dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+2);
else if ((a == b) && (b == num)) dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+1);
else if ((a != b) && (b != num) && (a != num)) dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+3);
else dp[i][b][num][c][d] = max(dp[i][b][num][c][d],dp[i-1][a][b][c][d]+2);
if ((c == 0) && (d == 0)) dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+1);
else if ((c == 0) && (d == num)) dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+1);
else if ((c == 0) && (d != num)) dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+2);
else if ((c == d) && (d == num)) dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+1);
else if ((c != d) && (d != num) && (c != num)) dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+3);
else dp[i][a][b][d][num] = max(dp[i][a][b][d][num],dp[i-1][a][b][c][d]+2);
}
}
}
}
}
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++) maxx = max(maxx,dp[n][a][b][c][d]);
cout << maxx << endl;
}
# | 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... |