#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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
456 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
456 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
348 KB |
Output is correct |
14 |
Execution timed out |
2075 ms |
348 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
456 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
348 KB |
Output is correct |
14 |
Execution timed out |
2075 ms |
348 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
456 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
348 KB |
Output is correct |
14 |
Execution timed out |
2075 ms |
348 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |