#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
int n;
string s;
bool used[maxn];
vector<pair<int,int>> v;
int best=0;
bool isect(pair<int,int> p, pair<int,int> q) {
if (max(p.first,q.first) >= min(p.second,q.second)) return false;
if (p.first>q.first) swap(p,q);
if (p.first<=q.first && q.second<=p.second) return false;
return true;
}
void eval() {
assert(int(v.size())==n/2);
for (auto &p: v) {
if (p.first>p.second) {
swap(p.first,p.second);
}
}
int res = 0;
for (int i=0; i<n/2; i++) {
for (int j=i+1; j<n/2; j++) {
if (isect(v[i],v[j])) res++;
}
}
// watch(res);
// for (auto p: v) {
// cout<<p.first<<" "<<p.second<<endl;
// }
best = max(best, res);
}
void dfs(int i) {
if (i == n) {
eval();
} else {
if (s[i]=='B') {
for (int j=0; j<n; j++) {
if (s[j]=='W') {
if (!used[j]) {
used[j]=true;
v.push_back({i,j});
dfs(i+1);
v.pop_back();
used[j]=false;
}
}
}
} else {
dfs(i+1);
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>s;
n *= 2;
dfs(0);
cout<<best<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
11 ms |
384 KB |
Output is correct |
10 |
Correct |
11 ms |
384 KB |
Output is correct |
11 |
Correct |
11 ms |
384 KB |
Output is correct |
12 |
Correct |
9 ms |
384 KB |
Output is correct |
13 |
Correct |
12 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
11 ms |
384 KB |
Output is correct |
10 |
Correct |
11 ms |
384 KB |
Output is correct |
11 |
Correct |
11 ms |
384 KB |
Output is correct |
12 |
Correct |
9 ms |
384 KB |
Output is correct |
13 |
Correct |
12 ms |
384 KB |
Output is correct |
14 |
Execution timed out |
2073 ms |
384 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
11 ms |
384 KB |
Output is correct |
10 |
Correct |
11 ms |
384 KB |
Output is correct |
11 |
Correct |
11 ms |
384 KB |
Output is correct |
12 |
Correct |
9 ms |
384 KB |
Output is correct |
13 |
Correct |
12 ms |
384 KB |
Output is correct |
14 |
Execution timed out |
2073 ms |
384 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
11 ms |
384 KB |
Output is correct |
10 |
Correct |
11 ms |
384 KB |
Output is correct |
11 |
Correct |
11 ms |
384 KB |
Output is correct |
12 |
Correct |
9 ms |
384 KB |
Output is correct |
13 |
Correct |
12 ms |
384 KB |
Output is correct |
14 |
Execution timed out |
2073 ms |
384 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |