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;
typedef long long ll;
const int N = 2e5 + 5;
int a[2*N];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
string s; cin >> s;
for (int i = 0; i < 2*n; i++)
a[i] = s[i] == 'B';
ll ans = 0;
for (int i = 0; i < n; i++) {
int ptr[2] = {i+n, i+n}, cnt[2] = {0, 0}, cntR[2] = {0, 0};
auto get = [&](int j) {
return j < 2*n ? j : j-2*n;
};
ll val = 0;
for (int j = i; j < i+n; j++) {
while (get(ptr[a[j]]) != i && a[get(ptr[a[j]])] == a[j])
cntR[a[j]]++, ptr[a[j]]++;
ptr[a[j]]++;
val += min(cntR[a[j]], cnt[a[j]^1]) + cnt[a[j]]++;
}
ans = max(ans, val);
}
cout << ans << "\n";
}
# | 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... |