# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
536380 | Monarchuwu | Monochrome Points (JOI20_monochrome) | C++17 | 2072 ms | 3540 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<iostream>
#include<algorithm>
#include<vector>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
const int N = 2e5 + 8;
int n, n2;
char s[N << 2];
char c[N << 1];
int solve(int l, int r) {
copy(s + l, s + r + 1, c + 1);
vector<int> vec[2];
for (int i = n; i; --i)
vec[c[i] == 'W'].push_back(i);
int sum(0);
for (int i = n + 1, x, y, p; i <= n2; ++i) {
x = c[i] == 'B';
y = vec[x].back(); vec[x].pop_back();
sum += vec[x].size();
sum += lower_bound(all(vec[x ^ 1]), y, greater<int>()) - vec[x ^ 1].begin();
}
return sum;
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n >> (s + 1);
n2 = n << 1;
copy(s + 1, s + n2 + 1, s + n2 + 1);
int ans(0);
for (int i = 1; i <= n; ++i)
ans = max(ans, solve(i, i + n2 - 1));
cout << ans << '\n';
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
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... |