#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define f first
#define s second
#define all(v) v.begin(), v.end()
// #define int ll
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
struct test
{
void solve()
{
int n;
cin >> n;
vector<int> b, w;
int bfk = 0;
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < 2 * n; ++i)
{
char x;
cin >> x;
if (x == 'B')
{
b.pb(i);
cnt1++;
}
else
{
w.pb(i);
cnt2++;
}
if (cnt1 == cnt2)
bfk++;
}
int res = 0;
for (int wtf = bfk - 10; wtf < bfk + 10; ++wtf)
{
int k = (wtf + 100 * n) % n;
vector<pii> segs;
for (int i = 0; i < n; ++i)
segs.pb({min(b[i], w[(i + k) % n]), max(b[i], w[(i + k) % n])});
sort(all(segs));
int cnt = 0;
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
{
cnt += (segs[j].f < segs[i].s and segs[i].s < segs[j].s);
}
res = max(res, cnt);
}
cout << res << "\n";
}
};
main()
{
test t;
t.solve();
}
Compilation message (stderr)
monochrome.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
66 | main()
| ^~~~
# | 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... |