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;
const int MN=1e5+2;
int N,dp[2][4][4][4][4],a[MN];
string s;
inline int calc(char x,char y,char z) {
return (x==1||y==1||z==1)+(x==2||y==2||z==2)+(x==3||y==3||z==3);
}
int main() {
ios::sync_with_stdio(0);cin.tie(0);
cin>>N>>s;
for(int i=0;i<N;++i) {
if(s[i]=='B') a[i+1]=1;
if(s[i]=='F') a[i+1]=2;
if(s[i]=='M') a[i+1]=3;
}
for(int i=0;i<2;++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]=INT_MIN;
dp[0][0][0][0][0]=0;
int ans=0;
for(int i=1;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&1][k][a[i]][l][m]=max(dp[i&1][k][a[i]][l][m],dp[(i-1)&1][j][k][l][m]+calc(a[i],j,k));
dp[i&1][j][k][m][a[i]]=max(dp[i&1][j][k][m][a[i]],dp[(i-1)&1][j][k][l][m]+calc(a[i],l,m));
ans=max({ans,dp[i&1][j][a[i]][l][m],dp[i&1][j][k][l][a[i]]});
}
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... |