답안 #492304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492304 2021-12-06T14:56:30 Z alextodoran Monochrome Points (JOI20_monochrome) C++17
35 / 100
2000 ms 4804 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int N;

string s;

vector <int> v[2];

bool intersect (int a1, int a2, int b1, int b2) {
    if (a1 > a2) {
        swap(a1, a2);
    }
    if (b1 > b2) {
        swap(b1, b2);
    }
    if (a1 < b1 && b1 < a2 && a2 < b2) {
        return true;
    }
    if (b1 < a1 && a1 < b2 && b2 < a2) {
        return true;
    }
    return false;
}

int solve (int offs) {
    vector <pair <int, int>> segments;
    for (int i = 0; i < N; i++) {
        int j = (i + offs) % N;
        segments.push_back(make_pair(v[0][i], v[1][j]));
    }
    int cnt = 0;
    for (int i = 0; i < (int) segments.size(); i++) {
        for (int j = i + 1; j < (int) segments.size(); j++) {
            cnt += intersect(segments[i].first, segments[i].second,
                             segments[j].first, segments[j].second);
        }
    }
    return cnt;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    cin >> s;

    for (int i = 0; i < N * 2; i++) {
        v[(s[i] == 'B')].push_back(i);
    }

    int l = 0, r = N - 1;
    while (l < r) {
        int mid = (l + r) / 2;
        if (solve(mid) < solve(mid + 1)) {
            l = mid + 1;
        } else {
            r = mid;
        }
    }

    cout << solve(l) << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 320 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 308 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 2 ms 204 KB Output is correct
31 Correct 2 ms 204 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 2 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 320 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 308 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 2 ms 204 KB Output is correct
31 Correct 2 ms 204 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 2 ms 312 KB Output is correct
34 Correct 65 ms 348 KB Output is correct
35 Correct 64 ms 332 KB Output is correct
36 Correct 63 ms 352 KB Output is correct
37 Correct 58 ms 332 KB Output is correct
38 Correct 53 ms 332 KB Output is correct
39 Correct 61 ms 332 KB Output is correct
40 Correct 62 ms 332 KB Output is correct
41 Correct 49 ms 332 KB Output is correct
42 Correct 62 ms 332 KB Output is correct
43 Correct 64 ms 332 KB Output is correct
44 Correct 57 ms 348 KB Output is correct
45 Correct 52 ms 332 KB Output is correct
46 Correct 68 ms 348 KB Output is correct
47 Correct 68 ms 332 KB Output is correct
48 Correct 63 ms 332 KB Output is correct
49 Correct 48 ms 352 KB Output is correct
50 Correct 57 ms 332 KB Output is correct
51 Correct 63 ms 332 KB Output is correct
52 Correct 61 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 320 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 2 ms 308 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 2 ms 204 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 2 ms 204 KB Output is correct
31 Correct 2 ms 204 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 2 ms 312 KB Output is correct
34 Correct 65 ms 348 KB Output is correct
35 Correct 64 ms 332 KB Output is correct
36 Correct 63 ms 352 KB Output is correct
37 Correct 58 ms 332 KB Output is correct
38 Correct 53 ms 332 KB Output is correct
39 Correct 61 ms 332 KB Output is correct
40 Correct 62 ms 332 KB Output is correct
41 Correct 49 ms 332 KB Output is correct
42 Correct 62 ms 332 KB Output is correct
43 Correct 64 ms 332 KB Output is correct
44 Correct 57 ms 348 KB Output is correct
45 Correct 52 ms 332 KB Output is correct
46 Correct 68 ms 348 KB Output is correct
47 Correct 68 ms 332 KB Output is correct
48 Correct 63 ms 332 KB Output is correct
49 Correct 48 ms 352 KB Output is correct
50 Correct 57 ms 332 KB Output is correct
51 Correct 63 ms 332 KB Output is correct
52 Correct 61 ms 332 KB Output is correct
53 Execution timed out 2084 ms 4804 KB Time limit exceeded
54 Halted 0 ms 0 KB -