이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, st, dr, mij;
vector<ll> A, B;
ll re(ll k) {
    ll r = 0;
    for(ll i = 0, d; i < n; ++i)
        d = abs(A[i] - B[(i + k) % n]), r += min(d, 2 * n - d) - 1;
    return r;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    string C;
    cin >> n >> C;
    for(ll i = 0; i < 2 * n; ++i) (C[i] != C[0] ? B : A).push_back(i);
    st = 0, dr = 2 * n - 1;
    while(st < dr) {
        mij = (st + dr + 1) / 2;
        if(re(mij) < re(mij + 1)) st = mij;
        else dr = mij - 1;
    }
    cout << max({re(st), re((st - 1 + 2 * n) % (2 * n)), re((st + 1) % (2 * n))}) / 2 << "\n";
    return 0;
}
| # | 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... |