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 n,x[100010];
int dp[2][4][4][4][4];
string s;
int cnt(int a,int b,int c){
int tmp=0;
if (a==1||b==1||c==1)tmp++;
if (a==2||b==2||c==2)tmp++;
if (a==3||b==3||c==3)tmp++;
return tmp;
}
int main(){
cin>>n>>s;
for (int i=0;i<n;i++){
if (s[i]=='M')x[i]=1;
else if (s[i]=='F')x[i]=2;
else x[i]=3;
}
int now=1;
memset(dp,-1,sizeof(dp));
dp[0][0][0][0][0]=0;
for (int k=0;k<n;k++){
memset(dp[now],-1,sizeof(dp[now]));
for (int a=0;a<=3;a++)
for (int b=0;b<=3;b++)
for (int c=0;c<=3;c++)
for (int d=0;d<=3;d++)
if(dp[1-now][a][b][c][d]!=-1){
dp[now][x[k]][a][c][d]=max(dp[now][x[k]][a][c][d],dp[1-now][a][b][c][d]+cnt(x[k],a,b));//LEFT
dp[now][a][b][x[k]][c]=max(dp[now][a][b][x[k]][c],dp[1-now][a][b][c][d]+cnt(x[k],c,d));
}
now=1-now;
}
int ans=-1;
for (int a=0;a<=3;a++)
for (int b=0;b<=3;b++)
for (int c=0;c<=3;c++)
for (int d=0;d<=3;d++)ans=max(ans,dp[1-now][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... |