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>
typedef long long ll;
using namespace std;
const int MX = 1e5 + 5;
ll dp[MX][4][4][4][4];
int N;
int score(int a, int b, int c)
{
int ret = 0;
if (a == 1 || b == 1 || c == 1)
ret++;
if (a == 2 || b == 2 || c == 2)
ret++;
if (a == 3 || b == 3 || c == 3)
ret++;
return ret;
}
int main()
{
cin >> N;
for (int i = 0; i <= N; i++)
for (int a = 0; a < 4; a++)
for (int b = 0; b < 4; b++)
for (int c = 0; c < 4; c++)
for (int d = 0; d < 4; d++)
dp[i][a][b][c][d] = -1;
dp[0][0][0][0][0] = 0;
string S;
cin >> S;
for (int i = 0; i < N; i++)
{
int x = 0;
if (S[i] == 'B')
x = 1;
if (S[i] == 'F')
x = 2;
if (S[i] == 'M')
x = 3;
for (int a = 0; a < 4; a++)
for (int b = 0; b < 4; b++)
for (int c = 0; c < 4; c++)
for (int d = 0; d < 4; d++)
{
if (dp[i][a][b][c][d] == -1)
continue;
dp[i + 1][a][b][d][x] = max(dp[i + 1][a][b][d][x], dp[i][a][b][c][d] + score(c, d, x));
dp[i + 1][b][x][c][d] = max(dp[i + 1][b][x][c][d], dp[i][a][b][c][d] + score(a, b, x));
}
}
ll ans = 0;
for (int a = 0; a < 4; a++)
for (int b = 0; b < 4; b++)
for (int c = 0; c < 4; c++)
for (int d = 0; d < 4; d++)
ans = max(ans, dp[N][a][b][c][d]);
cout << ans << '\n';
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... |