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 fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ld long double
#define pld pair<ld, ld>
#define pli pair<ld, int>
#define pii pair<int, int>
#define pis pair<int, string>
#define pl pair<ll, ll>
#define nl '\n'
using namespace std;
int N, DP[100007][4][4][4][4], A[100007];
string S, food="MFB";
int main(){
fastio;
memset(DP, -1, sizeof(DP));
cin >> N >> S;
for(int i=0; i<N; i++)
for(int j=0; j<3; j++)
if(S[i]==food[j])
A[i]=j;
DP[0][3][3][3][3]=0;
int ans=0;
for(int loc=0; loc<N; loc++)
for(int i=3; i>=0; i--)
for(int j=3; j>=0; j--)
for(int k=3; k>=0; k--)
for(int l=3; l>=0; l--){
int cnt=0, now=DP[loc][i][j][k][l];
if(now==-1)
continue;
bool ada[4]={0, 0, 0, 0};
ada[i]=ada[j]=ada[A[loc]]=1;
for(int ii=0; ii<3; ii++)
cnt+=ada[ii];
int &ret1=DP[loc+1][j][A[loc]][k][l];
ret1=max(ret1, cnt+now);
ada[0]=ada[1]=ada[2]=cnt=0;
ada[k]=ada[l]=ada[A[loc]]=1;
for(int ii=0; ii<3; ii++)
cnt+=ada[ii];
int &ret2=DP[loc+1][i][j][l][A[loc]];
ret2=max(ret2, cnt+now);
}
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++)
ans=max(ans, DP[N][i][j][k][l]);
cout << ans << nl;
}
Compilation message (stderr)
miners.cpp: In function 'int main()':
miners.cpp:46:49: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
46 | ada[0]=ada[1]=ada[2]=cnt=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... |