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;
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;
}
# | 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... |