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;
char remapeo[4]={' ','B','F','M'};
string comida;
int memo[100002][5][5][5][5];
int co(char x){
if(x=='B')return 1;
if(x=='F')return 2;
if(x=='M')return 3;
return 0;
}
int dif(int a,int b,int c){
int ans=1;
if(a!=b and !(a==0 or b==0))ans++;
if(a!=c and b!=c and !(b==0 or c==0))ans++;
return ans;
}
int dp(int i,int X1,int X2, int Y1,int Y2){
if(i==n)return 0;
if(memo[i][X1][X2][Y1][Y2]==-1){
memo[i][X1][X2][Y1][Y2]=max(dp(i+1,X2,co(comida[i]),Y1,Y2)+dif(X1,X2,co(comida[i])),dp(i+1,X1,X2,Y2,co(comida[i]))+dif(Y1,Y2,co(comida[i])));
}
return memo[i][X1][X2][Y1][Y2];
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
cin>>comida;
for(int i=0;i<=n;i++){
for(int j=0;j<=3;j++){
for(int k=0;k<=3;k++){
for(int l=0;l<=3;l++){
for(int y=0;y<=3;y++){
memo[i][j][k][l][y]=-1;
}
}
}
}
}
cout<<dp(0,0,0,0,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... |