답안 #362274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362274 2021-02-02T13:29:00 Z doowey Monochrome Points (JOI20_monochrome) C++14
35 / 100
2000 ms 10964 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)4e5 + 100;

int col[N];
int n, m;
vector<int> C[2];
int segt[N*2];

void upd(int id, int v){
    id += m;
    while(id > 0){
        segt[id] += v;
        id /= 2;
    }
}

int get(int l, int r){
    l += m;
    r += m;
    int cum = 0;
    while(l <= r){
        if(l % 2 == 1) cum += segt[l ++ ];
        if(r % 2 == 0) cum += segt[r -- ];
        l /= 2;
        r /= 2;
    }
    return cum;
}

ll f(int k){
    vector<pii> seg;
    for(int i = 0 ; i < n; i ++ ){
        seg.push_back(mp(C[0][i], C[1][(i + k) % n]));
    }
    for(auto &x : seg){
        if(x.fi > x.se) swap(x.fi, x.se);
    }
    for(int i = 0 ; i < m * 2; i ++ ){
        segt[i]=0;
    }
    sort(seg.begin(), seg.end());
    ll ff = 0;
    for(auto q : seg){
        ff += get(q.fi, q.se);
        upd(q.se, +1);
    }
    return ff;
}

int main(){
    fastIO;
    cin >> n;
    m = n * 2;
    char qf;
    for(int i = 0; i < m ; i ++ ){
        cin >> qf;
        if(qf == 'B'){
            col[i]=0;
        }
        else{
            col[i]=1;
        }
        C[col[i]].push_back(i);
    }
    ll high = 0;
    for(int i = 0 ; i < n; i ++ ){
        high = max(high, f(i));
    }
    cout << high << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 11 ms 364 KB Output is correct
15 Correct 11 ms 364 KB Output is correct
16 Correct 12 ms 384 KB Output is correct
17 Correct 11 ms 364 KB Output is correct
18 Correct 8 ms 364 KB Output is correct
19 Correct 8 ms 364 KB Output is correct
20 Correct 8 ms 364 KB Output is correct
21 Correct 8 ms 364 KB Output is correct
22 Correct 9 ms 364 KB Output is correct
23 Correct 5 ms 364 KB Output is correct
24 Correct 7 ms 364 KB Output is correct
25 Correct 7 ms 364 KB Output is correct
26 Correct 8 ms 364 KB Output is correct
27 Correct 9 ms 364 KB Output is correct
28 Correct 9 ms 364 KB Output is correct
29 Correct 7 ms 364 KB Output is correct
30 Correct 7 ms 364 KB Output is correct
31 Correct 9 ms 364 KB Output is correct
32 Correct 9 ms 364 KB Output is correct
33 Correct 9 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 11 ms 364 KB Output is correct
15 Correct 11 ms 364 KB Output is correct
16 Correct 12 ms 384 KB Output is correct
17 Correct 11 ms 364 KB Output is correct
18 Correct 8 ms 364 KB Output is correct
19 Correct 8 ms 364 KB Output is correct
20 Correct 8 ms 364 KB Output is correct
21 Correct 8 ms 364 KB Output is correct
22 Correct 9 ms 364 KB Output is correct
23 Correct 5 ms 364 KB Output is correct
24 Correct 7 ms 364 KB Output is correct
25 Correct 7 ms 364 KB Output is correct
26 Correct 8 ms 364 KB Output is correct
27 Correct 9 ms 364 KB Output is correct
28 Correct 9 ms 364 KB Output is correct
29 Correct 7 ms 364 KB Output is correct
30 Correct 7 ms 364 KB Output is correct
31 Correct 9 ms 364 KB Output is correct
32 Correct 9 ms 364 KB Output is correct
33 Correct 9 ms 364 KB Output is correct
34 Correct 531 ms 620 KB Output is correct
35 Correct 535 ms 620 KB Output is correct
36 Correct 509 ms 492 KB Output is correct
37 Correct 474 ms 620 KB Output is correct
38 Correct 354 ms 620 KB Output is correct
39 Correct 420 ms 620 KB Output is correct
40 Correct 383 ms 620 KB Output is correct
41 Correct 377 ms 620 KB Output is correct
42 Correct 511 ms 620 KB Output is correct
43 Correct 453 ms 492 KB Output is correct
44 Correct 423 ms 620 KB Output is correct
45 Correct 404 ms 620 KB Output is correct
46 Correct 434 ms 620 KB Output is correct
47 Correct 488 ms 620 KB Output is correct
48 Correct 443 ms 620 KB Output is correct
49 Correct 361 ms 492 KB Output is correct
50 Correct 372 ms 492 KB Output is correct
51 Correct 433 ms 620 KB Output is correct
52 Correct 430 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 11 ms 364 KB Output is correct
15 Correct 11 ms 364 KB Output is correct
16 Correct 12 ms 384 KB Output is correct
17 Correct 11 ms 364 KB Output is correct
18 Correct 8 ms 364 KB Output is correct
19 Correct 8 ms 364 KB Output is correct
20 Correct 8 ms 364 KB Output is correct
21 Correct 8 ms 364 KB Output is correct
22 Correct 9 ms 364 KB Output is correct
23 Correct 5 ms 364 KB Output is correct
24 Correct 7 ms 364 KB Output is correct
25 Correct 7 ms 364 KB Output is correct
26 Correct 8 ms 364 KB Output is correct
27 Correct 9 ms 364 KB Output is correct
28 Correct 9 ms 364 KB Output is correct
29 Correct 7 ms 364 KB Output is correct
30 Correct 7 ms 364 KB Output is correct
31 Correct 9 ms 364 KB Output is correct
32 Correct 9 ms 364 KB Output is correct
33 Correct 9 ms 364 KB Output is correct
34 Correct 531 ms 620 KB Output is correct
35 Correct 535 ms 620 KB Output is correct
36 Correct 509 ms 492 KB Output is correct
37 Correct 474 ms 620 KB Output is correct
38 Correct 354 ms 620 KB Output is correct
39 Correct 420 ms 620 KB Output is correct
40 Correct 383 ms 620 KB Output is correct
41 Correct 377 ms 620 KB Output is correct
42 Correct 511 ms 620 KB Output is correct
43 Correct 453 ms 492 KB Output is correct
44 Correct 423 ms 620 KB Output is correct
45 Correct 404 ms 620 KB Output is correct
46 Correct 434 ms 620 KB Output is correct
47 Correct 488 ms 620 KB Output is correct
48 Correct 443 ms 620 KB Output is correct
49 Correct 361 ms 492 KB Output is correct
50 Correct 372 ms 492 KB Output is correct
51 Correct 433 ms 620 KB Output is correct
52 Correct 430 ms 620 KB Output is correct
53 Execution timed out 2093 ms 10964 KB Time limit exceeded
54 Halted 0 ms 0 KB -