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>
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... |