이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> W, B;
    W.reserve(N);
    B.reserve(N);
    for (int i = 0; i < 2 * N; ++i) {
        char c;
        cin >> c;
        (c == 'W' ? W : B).push_back(i);
    }
    auto f = [&](int k) {
        ll ret = 0;
        for (int i = 0; i < N; ++i) {
            int j = i + k;
            if (j >= N) j -= N;
            int d = abs(W[i] - B[j]);  
            ret += min(d - 1, 2 * N - 1 - d);
        }
        return ret / 2;
    };
    ll ans = 0;
    for (int k = 0; k < N; ++k) {
        ans = max(ans, f(k));
    }
    cout << ans << '\n';
    // int min = -1, max = N;
    // int s = 1, t = 2;
    // while (min + t < max) swap(s += t, t);
    // int a = min, b = min + t, x = min + s;
    // ll fx = f(x), fy;
    // while (a + b != 2 * x) {
    //     int y = a + b - x;
    //     if (y < max and fx < (fy = f(y))) {
    //         fx = fy;
    //         b = x;
    //         x = y;
    //     } else {
    //         a = b;
    //         b = y;
    //     }
    // }
    // cout << fx << '\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... |