#include <bits/stdc++.h>
using namespace std;
int N,Ans;
string S;
int A[17];
bool Used[17];
int B[9][2];
bool g(int a,int b,int c,int d){
if (a>b)
swap(a,b);
if (c>d)
swap(c,d);
if (a>c){
swap(a,c);
swap(b,d);
}
return c<b&&b<d;
}
void f(int t){
int w=0;
for (int i=1; i<=N*2; i++){
if (!A[i]&&!Used[i]){
w=i;
break;
}
}
if (!w){
int tmp=0;
for (int i=1; i<=N; i++){
for (int j=i+1; j<=N; j++)
tmp+=g(B[i][0],B[i][1],B[j][0],B[j][1]);
}
Ans=max(Ans,tmp);
return;
}
Used[w]=true;
B[t][0]=w;
for (int i=1; i<=N*2; i++){
if (A[i]&&!Used[i]){
Used[i]=true;
B[t][1]=i;
f(t+1);
Used[i]=false;
}
}
Used[w]=false;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>N>>S;
for (int i=1; i<=N*2; i++)
A[i]=(S[i-1]=='B');
f(1);
cout<<Ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
9 ms |
316 KB |
Output is correct |
10 |
Correct |
8 ms |
312 KB |
Output is correct |
11 |
Correct |
9 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
312 KB |
Output is correct |
13 |
Correct |
10 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
9 ms |
316 KB |
Output is correct |
10 |
Correct |
8 ms |
312 KB |
Output is correct |
11 |
Correct |
9 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
312 KB |
Output is correct |
13 |
Correct |
10 ms |
316 KB |
Output is correct |
14 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
9 ms |
316 KB |
Output is correct |
10 |
Correct |
8 ms |
312 KB |
Output is correct |
11 |
Correct |
9 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
312 KB |
Output is correct |
13 |
Correct |
10 ms |
316 KB |
Output is correct |
14 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
2 ms |
204 KB |
Output is correct |
9 |
Correct |
9 ms |
316 KB |
Output is correct |
10 |
Correct |
8 ms |
312 KB |
Output is correct |
11 |
Correct |
9 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
312 KB |
Output is correct |
13 |
Correct |
10 ms |
316 KB |
Output is correct |
14 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |