이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int dp[100005][4][4][4][4];
int f(int x, int y, int z)
{
if (x)
{
if (x==y && y==z)
return 1;
else if ((x==y)^(y==z)^(z==x))
return 2;
else
return 3;
}
if (y)
{
if (y==z)
return 1;
else
return 2;
}
return 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, ans=0;
cin >> n;
for (int i=0; i<=n; i++)
for (int j=0; j<4; j++)
for (int k=0; k<4; k++)
for (int l=0; l<4; l++)
for (int m=0; m<4; m++)
dp[i][j][k][l][m]=-1e9;
dp[0][0][0][0][0]=0;
for (int i=1; i<=n; i++)
{
char c;
cin >> c;
int x=(c=='M'?1:(c=='F'?2:3));
for (int j=0; j<4; j++)
{
for (int k=0; k<4; k++)
{
for (int l=0; l<4; l++)
{
for (int m=0; m<4; m++)
{
dp[i][j][x][l][m]=max(dp[i][j][x][l][m], dp[i-1][k][j][l][m]+f(k, j, x));
// if (dp[i][j][x][l][m]>=1)
// cout << i << ' ' << j << ' ' << x << ' ' << l << ' ' << m << ' ' << dp[i][j][x][l][m] << '\n';
}
}
}
}
for (int j=0; j<4; j++)
{
for (int k=0; k<4; k++)
{
for (int l=0; l<4; l++)
{
for (int m=0; m<4; m++)
{
dp[i][j][k][l][x]=max(dp[i][j][k][l][x], dp[i-1][j][k][m][l]+f(m, l, x));
// if (dp[i][j][k][l][x]>=1)
// cout << i << ' ' << j << ' ' << k << ' ' << l << ' ' << x << ' ' << dp[i][j][k][l][x] << '\n';
}
}
}
}
}
for (int i=0; i<4; i++)
for (int j=0; j<4; j++)
for (int k=0; k<4; k++)
for (int l=0; l<4; l++)
ans=max(ans, dp[n][i][j][k][l]);
cout << ans;
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... |