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>
#define f(i) for (int i=0; i<4; i++)
using namespace std;
int dp[100005][4][4][4][4];
int d(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++)
f(j) f(k) f(l) f(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));
f(j) f(k) f(l) f(m)
{
dp[i][j][x][l][m]=max(dp[i][j][x][l][m], dp[i-1][k][j][l][m]+d(k, j, x));
dp[i][j][k][l][x]=max(dp[i][j][k][l][x], dp[i-1][j][k][m][l]+d(m, l, x));
}
}
f(i) f(j) f(k) f(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... |