이 제출은 이전 버전의 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; }
void printvector(vector<char>v){
for(auto x:v)cout<<x<<" ";
cout<<endl;
}
vector<char>a,b;
int x[3]={'M','F','B'};
int main(){_
int n;cin>>n;
string s;cin>>s;
int ans = 0;
for(int i=0;i<n;++i){
int p1=0,p2=0, j=max(sz(a)-2,0);
// cout<<"a ";
// printvector(a);
// cout<<"b ";
// printvector(b);
vector<char>tmp1,tmp2;
while(j<sz(a))tmp1.pb(a[j++]);
tmp1.pb(s[i]);
for(int k=0;k<3;++k){
int ok = 0;
for(auto l:tmp1)ok|=(l==x[k]);
p1+=ok;
}
j=max(sz(b)-2,0);
while(j<sz(b))tmp2.pb(b[j++]);
tmp2.pb(s[i]);
for(int k=0;k<3;++k){
int ok = 0;
for(auto l:tmp2)ok|=(l==x[k]);
p2+=ok;
}
if(p1>p2){
a = tmp1;
ans+=p1;
}else if(p1==p2){
if(sz(tmp1)<=sz(tmp2)){
a = tmp1, ans += p1;
}else if(sz(tmp1)>sz(tmp2)){
b = tmp2, ans += p2;
}
}else{
b = tmp2;
ans+=p2;
}
}
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... |