답안 #1088922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088922 2024-09-15T14:34:10 Z Wansur Monochrome Points (JOI20_monochrome) C++14
100 / 100
1411 ms 7716 KB
#include <bits/stdc++.h>
#define ent '\n'
//#define int long long

using namespace std;
typedef long long ll;
const int maxn = 2e5 + 12;

int t[maxn * 2];
int a[maxn], b[maxn];
int n, m, k;

void upd(int i, int x){
    for(; i <= n * 2;i |= i + 1){
        t[i] += x;
    }
}

int GET(int i){
    int ans = 0;
    for(; i > 0; i = (i & (i + 1)) - 1){
        ans += t[i];
    }
    return ans;
}

int get(int l, int r){
    return GET(r) - GET(l - 1);
}

ll get(int k){
    for(int i=1;i<=n*2;i++){
        t[i] = 0;
    }
    vector<pair<int, int>> v;
    for(int i=0;i<n;i++){
        v.push_back({min(a[i], b[(i + k) % n]), max(a[i], b[(i + k) % n])});
    }
    sort(v.begin(), v.end());
    ll ans = 0;
    for(auto [l, r] : v){
        ans += get(l, r);
        upd(r, 1);
    }
    return ans;
}

void solve(){
    cin >> n;
    int l = 0, r = 0;
    ll ans = 0;
    for(int i=1;i<=2*n;i++){
        char c;
        cin >> c;
        if(c == 'W') a[l++] = i;
        else b[r++] = i;
    }
    l = 1, r = n;
    while(r - l > 3){
        int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
        ll x = get(m1), y = get(m2);
        ans = max({ans, x, y});
        if(x < y) l = m1;
        else r = m2;
    }
    for(int i=l;i<=r;i++){
        ans = max(ans, get(i));
    }
    cout << ans << ent;
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }
}

Compilation message

monochrome.cpp: In function 'll get(int)':
monochrome.cpp:41:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |     for(auto [l, r] : v){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 440 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 440 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 484 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 440 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 484 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 5 ms 344 KB Output is correct
35 Correct 7 ms 348 KB Output is correct
36 Correct 5 ms 348 KB Output is correct
37 Correct 5 ms 540 KB Output is correct
38 Correct 3 ms 548 KB Output is correct
39 Correct 4 ms 348 KB Output is correct
40 Correct 3 ms 348 KB Output is correct
41 Correct 4 ms 548 KB Output is correct
42 Correct 6 ms 348 KB Output is correct
43 Correct 6 ms 348 KB Output is correct
44 Correct 6 ms 544 KB Output is correct
45 Correct 6 ms 348 KB Output is correct
46 Correct 5 ms 348 KB Output is correct
47 Correct 4 ms 544 KB Output is correct
48 Correct 4 ms 348 KB Output is correct
49 Correct 3 ms 348 KB Output is correct
50 Correct 5 ms 348 KB Output is correct
51 Correct 3 ms 348 KB Output is correct
52 Correct 5 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 440 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 484 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 5 ms 344 KB Output is correct
35 Correct 7 ms 348 KB Output is correct
36 Correct 5 ms 348 KB Output is correct
37 Correct 5 ms 540 KB Output is correct
38 Correct 3 ms 548 KB Output is correct
39 Correct 4 ms 348 KB Output is correct
40 Correct 3 ms 348 KB Output is correct
41 Correct 4 ms 548 KB Output is correct
42 Correct 6 ms 348 KB Output is correct
43 Correct 6 ms 348 KB Output is correct
44 Correct 6 ms 544 KB Output is correct
45 Correct 6 ms 348 KB Output is correct
46 Correct 5 ms 348 KB Output is correct
47 Correct 4 ms 544 KB Output is correct
48 Correct 4 ms 348 KB Output is correct
49 Correct 3 ms 348 KB Output is correct
50 Correct 5 ms 348 KB Output is correct
51 Correct 3 ms 348 KB Output is correct
52 Correct 5 ms 348 KB Output is correct
53 Correct 1342 ms 7600 KB Output is correct
54 Correct 1354 ms 7600 KB Output is correct
55 Correct 1242 ms 7356 KB Output is correct
56 Correct 1213 ms 7412 KB Output is correct
57 Correct 934 ms 7716 KB Output is correct
58 Correct 862 ms 7596 KB Output is correct
59 Correct 956 ms 7384 KB Output is correct
60 Correct 1038 ms 7420 KB Output is correct
61 Correct 1204 ms 7532 KB Output is correct
62 Correct 1036 ms 7492 KB Output is correct
63 Correct 1249 ms 7432 KB Output is correct
64 Correct 792 ms 7404 KB Output is correct
65 Correct 1234 ms 7240 KB Output is correct
66 Correct 1172 ms 7352 KB Output is correct
67 Correct 1194 ms 7348 KB Output is correct
68 Correct 817 ms 7124 KB Output is correct
69 Correct 883 ms 7700 KB Output is correct
70 Correct 872 ms 7160 KB Output is correct
71 Correct 1234 ms 7592 KB Output is correct
72 Correct 706 ms 7596 KB Output is correct
73 Correct 1411 ms 7600 KB Output is correct