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;
#define ff first
#define ss second
#define pb push_back
const int N=1e5+5;
int dp[4][4][4][4][N];
int mp[500];
signed main(){
mp['M'-'A']=1;
mp['F'-'A']=2;
mp['B'-'A']=3;
int n;
string s;
cin>>n>>s;
int h=mp[s[0]-'A'];
for(int i=0;i<n;i++){
for(int x1=0;x1<4;x1++){
for(int y1=0;y1<4;y1++){
for(int x2=0;x2<4;x2++){
for(int y2=0;y2<4;y2++){
dp[x1][y1][x2][y2][i]=-1e9;
}
}
}
}
}
dp[0][h][0][0][0]=1;
dp[0][0][0][h][0]=1;
for(int i=1;i<n;i++){
int k=mp[s[i]-'A'];
for(int x1=0;x1<4;x1++){
for(int y1=0;y1<4;y1++){
for(int x2=0;x2<4;x2++){
for(int y2=0;y2<4;y2++){
int h=2;
dp[y1][k][x2][y2][i]=max(dp[y1][k][x2][y2][i],dp[x1][y1][x2][y2][i-1]+h);
h=2;
dp[x1][y1][y2][k][i]=max(dp[x1][y1][y2][k][i],dp[x1][y1][x2][y2][i-1]+h);
}
}
}
}
}
int mx=0;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
for(int k=0;k<4;k++){
for(int l=0;l<4;l++){
mx=max(mx,dp[i][j][k][l][n-1]);
}
}
}
}
cout<<mx;
}
# | 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... |