답안 #710595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710595 2023-03-15T11:57:25 Z KoD Monochrome Points (JOI20_monochrome) C++17
35 / 100
2000 ms 2272 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 10 ms 340 KB Output is correct
35 Correct 10 ms 340 KB Output is correct
36 Correct 13 ms 328 KB Output is correct
37 Correct 10 ms 340 KB Output is correct
38 Correct 9 ms 340 KB Output is correct
39 Correct 11 ms 212 KB Output is correct
40 Correct 9 ms 320 KB Output is correct
41 Correct 8 ms 336 KB Output is correct
42 Correct 10 ms 340 KB Output is correct
43 Correct 9 ms 340 KB Output is correct
44 Correct 8 ms 324 KB Output is correct
45 Correct 8 ms 336 KB Output is correct
46 Correct 9 ms 336 KB Output is correct
47 Correct 9 ms 320 KB Output is correct
48 Correct 9 ms 212 KB Output is correct
49 Correct 10 ms 344 KB Output is correct
50 Correct 10 ms 340 KB Output is correct
51 Correct 9 ms 340 KB Output is correct
52 Correct 10 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 10 ms 340 KB Output is correct
35 Correct 10 ms 340 KB Output is correct
36 Correct 13 ms 328 KB Output is correct
37 Correct 10 ms 340 KB Output is correct
38 Correct 9 ms 340 KB Output is correct
39 Correct 11 ms 212 KB Output is correct
40 Correct 9 ms 320 KB Output is correct
41 Correct 8 ms 336 KB Output is correct
42 Correct 10 ms 340 KB Output is correct
43 Correct 9 ms 340 KB Output is correct
44 Correct 8 ms 324 KB Output is correct
45 Correct 8 ms 336 KB Output is correct
46 Correct 9 ms 336 KB Output is correct
47 Correct 9 ms 320 KB Output is correct
48 Correct 9 ms 212 KB Output is correct
49 Correct 10 ms 344 KB Output is correct
50 Correct 10 ms 340 KB Output is correct
51 Correct 9 ms 340 KB Output is correct
52 Correct 10 ms 340 KB Output is correct
53 Execution timed out 2073 ms 2272 KB Time limit exceeded
54 Halted 0 ms 0 KB -