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 fi first
#define se second
#define rep(a, b) for(int a = 0; a < (int)(b); a++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e5+10;
int dp[N][4][4][4][4];
string s;
//M=0,F=1,B=2
void ob(int k){
int num=(s[k]=='M'?0:(s[k]=='F'?1:2));
rep(i,4) rep(j,4) rep(x,4) rep(y,4){
bool c[4];
c[0]=0,c[1]=0,c[2]=0,c[3]=0;
c[i]=1,c[j]=1,c[num]=1;
int diff1=c[0]+c[1]+c[2];
c[i]=0,c[j]=0,c[num]=0,c[num]=1,c[x]=1,c[y]=1;
int diff2=c[0]+c[1]+c[2];
dp[k][i][j][x][y]=max(dp[k+1][num][i][x][y]+diff1,dp[k+1][i][j][num][x]+diff2);
}
}
void solve(){
int n;
cin>>n;
cin>>s;
for(int i=s.size()-1;i>=0;i--) ob(i);
int res=0;
cout<<dp[0][3][3][3][3]<<"\n";
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
solve();
}
Compilation message (stderr)
miners.cpp: In function 'void solve()':
miners.cpp:30:6: warning: unused variable 'res' [-Wunused-variable]
30 | int res=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... |