이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
int main(){_
int n;cin>>n;
string s;cin>>s;
dp[0][{"",""}] = -1;
for(int i=1;i<=n;++i){
for(auto [a,b]:dp[(i-1)&1]){
auto [x,y] = a;
if(x==y&&sz(x)==0)b = 0;
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';
}
ckmax(dp[i&1][{newa,y}],b+cntm+cntf+cntb);
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';
}
ckmax(dp[i&1][{x,newb}],b+cntm+cntf+cntb);
}
}
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... |