이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |