# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
411574 | nichke | Monochrome Points (JOI20_monochrome) | C++14 | 2074 ms | 14724 KiB |
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;
#define int long long
#define endl '\n'
int ans;
int n;
string s;
vector<int> a, b;
int bit[400005];
void clr() {
for (int i = 1; i <= 2 * n; i++) {
bit[i] = 0;
}
}
void upd(int v, int k) {
while (v <= 2 * n) {
bit[v] += k;
v += (v & (-v));
}
}
int qry(int v) {
int res = 0;
while (v) {
res += bit[v];
v -= (v & (-v));
}
return res;
}
int sum(int l, int r) {
return qry(r) - qry(l - 1);
}
int calc(int k) {
int res = 0;
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
v.push_back({a[i], b[(i + k) % n]});
}
for (int i = 0; i < v.size(); i++) {
if (v[i].first > v[i].second) {
swap(v[i].first, v[i].second);
}
}
sort(v.begin(), v.end());
clr();
for (int i = 0; i < v.size(); i++) {
res += sum(v[i].first, v[i].second);
upd(v[i].second, 1);
}
return res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s;
for (int i = 0; i < 2 * n; i++) {
if (s[i] == 'W') {
a.push_back(i + 1);
} else {
b.push_back(i + 1);
}
}
for (int i = 0; i < n; i++) {
ans = max(ans, calc(i));
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | 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... |