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 = 400000 + 7;
int n;
string s;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> s;
vector<int> a, b;
for (int i = 0; i < 2 * n; i++) {
if (s[i] != s[0]) {
a.push_back(i);
}
else {
b.push_back(i);
}
}
vector<ll> cnt(n);
for (int shift = 0; shift < n; shift++) {
for (int i = 0; i < n; i++) {
int i2 = (i + shift) % n, l = min(a[i], b[i2]), r = max(a[i], b[i2]);
int inside = r - l - 1;
int outside = 2 * n - inside - 2;
cnt[shift] += min(inside, outside);
}
}
ll sol = 0;
for (auto& x : cnt) {
sol = max(sol, x);
}
cout << sol / 2 << "\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... |