답안 #527641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527641 2022-02-17T21:19:53 Z ajpiano Monochrome Points (JOI20_monochrome) C++17
35 / 100
2000 ms 4280 KB
//https://oj.uz/problem/view/JOI20_monochrome
#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second

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

struct bit{
    vector<int> fen;
    int sz = 0;
    bit (int n){
        sz = n+5; fen.resize(sz);
    }

    void add(int pos){
        pos++;
        for(; pos < sz; pos += pos&-pos) fen[pos]++;
    }

    int asum(int pos){
        pos++;
        int ans = 0;
        for(; pos > 0; pos -= pos&-pos) ans += fen[pos];
        return ans;
    }
    int sum(int l, int r){
        return asum(r)-asum(l);
    }
};

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    vector<int> pb(n), pw(n);
    int b = 0, w  = 0;
    for(int i = 0; i < 2*n; i++){
        if(s[i] == 'B') pb[b++] = i;
        else pw[w++] = i;
    }
    int fans = 0;
    for(int skip = 0; skip < n; skip++){
        b = 0, w = 0;
        bit ssum(2*n);
        int ans = 0;
        for(int i = 0; i < 2*n; i++){
            int goal = 0;
            if(s[i] == 'B'){
                goal = b-skip;
                if(goal < 0) goal += n;
                goal = pw[goal];
                b++;
            }else{
                goal = w+skip;
                if(goal >= n) goal -= n;
                goal = pb[goal];
                w++;
            }
            if(goal < i) continue;
            ans += ssum.sum(i,goal);
            ssum.add(goal);
        }
        fans = max(fans, ans);
    }
    cout << fans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 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 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 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 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 5 ms 204 KB Output is correct
15 Correct 5 ms 316 KB Output is correct
16 Correct 6 ms 312 KB Output is correct
17 Correct 4 ms 204 KB Output is correct
18 Correct 4 ms 204 KB Output is correct
19 Correct 3 ms 204 KB Output is correct
20 Correct 3 ms 204 KB Output is correct
21 Correct 3 ms 204 KB Output is correct
22 Correct 3 ms 312 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 4 ms 308 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 3 ms 204 KB Output is correct
27 Correct 3 ms 312 KB Output is correct
28 Correct 3 ms 312 KB Output is correct
29 Correct 3 ms 204 KB Output is correct
30 Correct 2 ms 204 KB Output is correct
31 Correct 3 ms 204 KB Output is correct
32 Correct 3 ms 204 KB Output is correct
33 Correct 3 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 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 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 5 ms 204 KB Output is correct
15 Correct 5 ms 316 KB Output is correct
16 Correct 6 ms 312 KB Output is correct
17 Correct 4 ms 204 KB Output is correct
18 Correct 4 ms 204 KB Output is correct
19 Correct 3 ms 204 KB Output is correct
20 Correct 3 ms 204 KB Output is correct
21 Correct 3 ms 204 KB Output is correct
22 Correct 3 ms 312 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 4 ms 308 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 3 ms 204 KB Output is correct
27 Correct 3 ms 312 KB Output is correct
28 Correct 3 ms 312 KB Output is correct
29 Correct 3 ms 204 KB Output is correct
30 Correct 2 ms 204 KB Output is correct
31 Correct 3 ms 204 KB Output is correct
32 Correct 3 ms 204 KB Output is correct
33 Correct 3 ms 204 KB Output is correct
34 Correct 179 ms 332 KB Output is correct
35 Correct 181 ms 336 KB Output is correct
36 Correct 175 ms 336 KB Output is correct
37 Correct 165 ms 456 KB Output is correct
38 Correct 114 ms 336 KB Output is correct
39 Correct 126 ms 328 KB Output is correct
40 Correct 112 ms 336 KB Output is correct
41 Correct 119 ms 336 KB Output is correct
42 Correct 184 ms 340 KB Output is correct
43 Correct 134 ms 336 KB Output is correct
44 Correct 124 ms 336 KB Output is correct
45 Correct 125 ms 336 KB Output is correct
46 Correct 142 ms 336 KB Output is correct
47 Correct 140 ms 312 KB Output is correct
48 Correct 129 ms 336 KB Output is correct
49 Correct 109 ms 340 KB Output is correct
50 Correct 130 ms 332 KB Output is correct
51 Correct 138 ms 336 KB Output is correct
52 Correct 149 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 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 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 5 ms 204 KB Output is correct
15 Correct 5 ms 316 KB Output is correct
16 Correct 6 ms 312 KB Output is correct
17 Correct 4 ms 204 KB Output is correct
18 Correct 4 ms 204 KB Output is correct
19 Correct 3 ms 204 KB Output is correct
20 Correct 3 ms 204 KB Output is correct
21 Correct 3 ms 204 KB Output is correct
22 Correct 3 ms 312 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 4 ms 308 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 3 ms 204 KB Output is correct
27 Correct 3 ms 312 KB Output is correct
28 Correct 3 ms 312 KB Output is correct
29 Correct 3 ms 204 KB Output is correct
30 Correct 2 ms 204 KB Output is correct
31 Correct 3 ms 204 KB Output is correct
32 Correct 3 ms 204 KB Output is correct
33 Correct 3 ms 204 KB Output is correct
34 Correct 179 ms 332 KB Output is correct
35 Correct 181 ms 336 KB Output is correct
36 Correct 175 ms 336 KB Output is correct
37 Correct 165 ms 456 KB Output is correct
38 Correct 114 ms 336 KB Output is correct
39 Correct 126 ms 328 KB Output is correct
40 Correct 112 ms 336 KB Output is correct
41 Correct 119 ms 336 KB Output is correct
42 Correct 184 ms 340 KB Output is correct
43 Correct 134 ms 336 KB Output is correct
44 Correct 124 ms 336 KB Output is correct
45 Correct 125 ms 336 KB Output is correct
46 Correct 142 ms 336 KB Output is correct
47 Correct 140 ms 312 KB Output is correct
48 Correct 129 ms 336 KB Output is correct
49 Correct 109 ms 340 KB Output is correct
50 Correct 130 ms 332 KB Output is correct
51 Correct 138 ms 336 KB Output is correct
52 Correct 149 ms 336 KB Output is correct
53 Execution timed out 2089 ms 4280 KB Time limit exceeded
54 Halted 0 ms 0 KB -