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>
using namespace std;
int inter(int a,int b,int c,int d){
if(a>b)swap(a,b);
if(c>d)swap(c,d);
if(a<c&&c<b&&b<d)
return 1;
if(c<a&&a<d&&d<b)
return 1;
return 0;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int n;
string str;
cin>>n>>str;
vector<int>blk,wht;
for(int i=0;i<2*n;i++)
if(str[i]=='B')
blk.push_back(i+1);
else wht.push_back(i+1);
int ans=-1;
vector<int>bst;
do {
int tmp=0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(inter(blk[i],wht[i],blk[j],wht[j]))
tmp++;
if(tmp>ans)
ans=tmp,bst=wht;
}while(next_permutation(wht.begin(),wht.end()));
cout<<ans<<'\n';
for(int i=0;i<n;i++);
//cerr<<"("<<blk[i]<<','<<bst[i]<<")\n";
}
# | 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... |