#include <bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define all(x) x.begin(), x.end()
#define sz(a) ((int) a.size())
#define pb push_back
#define fst first
#define snd second
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;cin>>n;
string s;cin>>s;
int m=n*2;
vector<int>w,v;
L(i,0,m-1){
if(s[i]=='B')v.pb(i);
else w.pb(i);
}
ll ans=0;
do{
bool valid=true;
vector<pair<int,int>>p;
if(!valid)continue;
//~ cout<<"NEW CASE=============="<<endl;
L(i,0,n-1){
int a=v[i],b=w[i];
if(a>b)swap(a,b);
p.pb({a,b});
}
ll cur=0;
//~ L(i,0,n-1){
//~ cout<<p[i].fst+1<<" "<<p[i].snd+1<<endl;
//~ }
L(i,0,n-1){
for(int j=i+1;j<n;j++){
//me fijo si se intersectan
int a=p[i].fst,b=p[i].snd;
int c=p[j].fst,d=p[j].snd;
//~ cout<<"RECTAS:"<<endl;
//~ cout<<a+1<<" "<<b+1<<endl;
//~ cout<<c+1<<" "<<d+1<<endl;
bool caso1=(b>c&&a>c&&d>a&&d<b),caso2=(a<d&&a<c&&b>c&&b<d);
if(caso1||caso2){
cur++;
}
}
}
ans=max(ans,cur);
}while(next_permutation(all(v)));
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... |