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 <iostream>
using namespace std;
int n,dp[2][4][4][4][4],a[100005];
int find(int x,int y,int z)
{
int t=0;
for(int i=1;i<=3;i++)if(x==i || y==i || z==i)t++;
return t;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++)
{
char c;
cin>>c;
if(c=='M')a[i]=1;
if(c=='F')a[i]=2;
if(c=='B')a[i]=3;
}
int d=1,e=0;
for(int i=n;i>=0;i--)
{
swap(d,e);
for(int j=0;j<=3;j++)
{
for(int k=0;k<=3;k++)
{
for(int l=0;l<=3;l++)
{
for(int m=0;m<=3;m++)
{
dp[d][j][k][l][m]=max(dp[e][k][a[i]][l][m]+find(j,k,a[i]),dp[e][j][k][m][a[i]]+find(l,m,a[i]));
}
}
}
}
}
cout<<dp[d][0][0][0][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... |