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 maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
map<pair<string,string>,int>dp[2];
map<pair<string,string>,bool>mark,mark2;
int main(){_
int n;cin>>n;
string s;cin>>s;
mark[{"",""}]=1;
for(int i=1;i<=n;++i){
for(auto [p,z]:mark){
auto [x,y] = p;
int b = dp[(i-1)&1][{x,y}];
int j = max(0,sz(x)-2),cntm=0,cntf=0,cntb=0;
string newa,newb;
while(j<sz(x))newa+=x[j++];
newa+=s[i];
for(auto u:newa){
cntm|=u=='M',cntf|=u=='F',cntb|=u=='B';
}
if(!mark2[{newa,y}])mark2[{newa,y}] = 1,dp[i&1][{newa,y}] = b+cntm+cntf+cntb;
else ckmax(dp[i&1][{newa,y}],b+cntm+cntb+cntf);
j = max(0,sz(y)-2), cntm = cntf = cntb = 0;
while(j<sz(y))newb+=y[j++];
newb+=s[i];
for(auto u:newb){
cntm|=u=='M',cntf|=u=='F',cntb|=u=='B';
}
if(!mark2[{x,newb}])mark2[{x,newb}]=1,dp[i&1][{x,newb}] = b+cntm+cntf+cntb;
else ckmax(dp[i&1][{x,newb}],b+cntm+cntb+cntf);
}
mark = mark2;mark2.clear();
}
int ans = 0;
for(auto [a,b]:dp[n&1])ckmax(ans,b);
cout<<ans<<endl;
};
# | 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... |