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<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<numeric>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
const int N = 25 + 8, inf = 0x80808080;
int n, n2;
char s[N << 1];
vector<int> B, W;
bool inside(int l, int r, int p) {
return (p - l) * (ll)(p - r) < 0;
}
int p[N];
int calc() {
// B[i], W[p[i]]
int ans(0);
for (int i = 0; i < n; ++i)
for (int j = 0; j < i; ++j)
ans += inside(B[i], W[p[i]], B[j]) ^ inside(B[i], W[p[i]], W[p[j]]);
return ans;
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n >> (s + 1);
n2 = n << 1;
for (int i = 1; i <= n2; ++i) {
if (s[i] == 'B')
B.push_back(i);
else W.push_back(i);
}
iota(p, p + n, 0);
int ans(0);
do {
ans = max(ans, calc());
} while (next_permutation(p, p + n));
cout << ans << '\n';
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
# | 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... |