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 ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back
#define ss second
#define ff first
#define ext exit(0)
using namespace std;
int n,i,j,p,t,k,a,dp[100001][4][4][4][4],ans;
string s;
inline int sol(int o, int oo , int ooo){
if(o==oo && oo==ooo) return 1;
else if(o==oo || o==ooo || ooo==oo) return 2;
else return 3;
}
int main (){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>s;
for(i=0;i<n;i++){
if(s[i]=='M') a=0;
else if(s[i]=='B') a=1;
else a=2;
for(j=0;j<3;j++){
for(k=0;k<3;k++){
for(t=0;t<3;t++){
for(p=0;p<3;p++){
dp[i+1][k][a][t][p]=max(dp[i+1][k][a][t][p],dp[i][j][k][t][p]+sol(k,a,j));
dp[i+1][j][k][p][a]=max(dp[i+1][j][k][p][a],dp[i][j][k][t][p]+sol(t,a,p));
}
}
}
}
}
for(j=0;j<3;j++){
for(k=0;k<3;k++){
for(t=0;t<3;t++){
for(p=0;p<3;p++) ans=max(ans,dp[n][j][k][t][p]-6);
}
}
}
cout<<ans;
}
# | 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... |