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>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD=1e9+7;
//typedef pair<ll,ll>Point;
//typedef pair<ll,ll>Line;
//#define x first
//#define y second
int n;
string str;
int get_val(int a,int b,int c){
int res=1;
if(a==b||b==c||a==c)
res=2;
if(a==b&&b==c)
res=3;
return res;
}
bool dpt[4][4][4][4][100000];
int dp[4][4][4][4][100000];
int get(int m1,int m2,int m3,int m4,int i){
if(i==n)
return 0;
if(dpt[m1][m2][m3][m4][i])
return dp[m1][m2][m3][m4][i];
int curr=0;
if(str[i]=='M')
curr=1;
if(str[i]=='B')
curr=2;
if(str[i]=='F')
curr=3;
int r1=get(m2,curr,m3,m4,i+1)+get_val(m1,m2,curr);
int r2=get(m1,m2,m4,curr,i+1)+get_val(m1,m2,curr);
dpt[m1][m2][m3][m4][i]=true;
dp[m1][m2][m3][m4][i]=max(r1,r2);
return max(r1,r2);
}
int main(){
ios::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
cin>>n;
cin>>str;
cout<<get(0,0,0,0,0)<<"\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... |