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