#include <bits/stdc++.h>
#define fst first
#define snd second
#define pb push_back
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define forn(i,a,b) for(int i = a; i<b; i++)
#define mset(a,v) memset(a,v,sizeof(a))
using namespace std;
typedef long long ll;
ll n;
int main(){
cin>>n;
string s; cin>>s;
vector<ll> b;
vector<ll> w;
forn(i,0,2*n){
if(s[i]=='B'){
b.pb(i);
}else{
w.pb(i);
}
}
ll res = 0;
forn(k,0,n){
ll cnt = 0;
vector<pair<pair<ll,ll>,ll>> line;
forn(i,0,SZ(b)){
ll j=k;
line.pb({{b[i],w[j]},0});
k++;
k%=n;
}
vector<pair<pair<ll,ll>,ll>> newline;
forn(i,0,SZ(line)){
line[i].snd=i;
if(line[i].fst.fst>line[i].fst.snd)
swap(line[i].fst.fst,line[i].fst.snd);
}
sort(ALL(line));
cnt=0;
forn(i,0,SZ(line)){
forn(j,i+1,SZ(line)){
if(line[i].snd==line[j].snd) continue;
if(line[j].fst.snd>line[i].fst.fst && line[j].fst.snd<line[i].fst.snd && line[j].fst.fst<line[i].fst.fst){
cnt++;
}else if(line[j].fst.fst>line[i].fst.fst && line[j].fst.fst<line[i].fst.snd && line[j].fst.snd>line[i].fst.snd){
cnt++;
}
}
}
res=max(res,cnt);
}
cout<<res<<'\n';
return 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... |