답안 #628456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628456 2022-08-13T12:08:33 Z MohamedFaresNebili Monochrome Points (JOI20_monochrome) C++14
35 / 100
1177 ms 16988 KB
#include <bits/stdc++.h>
 
            using namespace std;
 
            using ll = long long;
            using ld = long double;
            using pi = pair<pair<int, int>, pair<int, int>>;
 
            #define ff first
            #define ss second
            #define pb push_back
            #define all(x) (x).begin(), (x).end()
            #define lb lower_bound
 
            int N, ST[400005]; string S;
            vector<int> A, B;
            void update(int p, int v) {
                for(; p <= 2 * N; p += (p & (-p)))
                    ST[p] += v;
            }
            int query(int p) {
                int res = 0;
                for(; p; p -= (p & (-p)))
                    res += ST[p];
                return res;
            }
            int query(int lo, int hi) {
                return query(hi) - query(lo - 1);
            }
 
            int solve(int v) {
                vector<pair<int, int>> P;
                for(int l = 0; l < N; l++)
                    P.push_back({A[l], B[(l + v) % N]});
                int arr[2 * N]{0};
                for(int l = 0; l < N; l++) {
                    arr[A[l]] = l, arr[B[(l + v) % N]] = l;
                }
                for(int l = 0; l <= 2 * N; l++) ST[l] = 0;
                int res = 0; unordered_map<int, int> M;
                for(int l = 0; l < 2 * N; l++) {
                    if(M.find(arr[l]) != M.end()) {
                        int i = M[arr[l]];
                        update(i, -1); res += query(i, l + 1);
                        continue;
                    }
                    update(l + 1, 1); M[arr[l]] = l + 1;
                }
                return res;
            }
 
            int32_t main() {
                ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
                cin >> N >> S; int res = 0;
                for(int l = 0; l < 2 * N; l++) {
                    if(S[l] == 'B') A.push_back(l);
                    if(S[l] == 'W') B.push_back(l);
                }
                int lo = 0, hi = N - 1;
                while(lo <= hi) {
                    int md = (lo + hi) / 2;
                    int U = solve(md), V = solve(md + 1);
                    if(V > U) { lo = md + 1, res = max(res, V); }
                    else hi = md - 1, res = max(res, U);
                }
                cout << res << "\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 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 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 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 7 ms 476 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 6 ms 476 KB Output is correct
37 Correct 6 ms 468 KB Output is correct
38 Correct 5 ms 340 KB Output is correct
39 Correct 6 ms 468 KB Output is correct
40 Correct 6 ms 468 KB Output is correct
41 Correct 5 ms 340 KB Output is correct
42 Correct 7 ms 480 KB Output is correct
43 Correct 8 ms 488 KB Output is correct
44 Correct 6 ms 468 KB Output is correct
45 Correct 7 ms 468 KB Output is correct
46 Correct 8 ms 468 KB Output is correct
47 Correct 7 ms 468 KB Output is correct
48 Correct 7 ms 596 KB Output is correct
49 Correct 5 ms 340 KB Output is correct
50 Correct 6 ms 468 KB Output is correct
51 Correct 6 ms 480 KB Output is correct
52 Correct 6 ms 476 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 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 7 ms 476 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 6 ms 476 KB Output is correct
37 Correct 6 ms 468 KB Output is correct
38 Correct 5 ms 340 KB Output is correct
39 Correct 6 ms 468 KB Output is correct
40 Correct 6 ms 468 KB Output is correct
41 Correct 5 ms 340 KB Output is correct
42 Correct 7 ms 480 KB Output is correct
43 Correct 8 ms 488 KB Output is correct
44 Correct 6 ms 468 KB Output is correct
45 Correct 7 ms 468 KB Output is correct
46 Correct 8 ms 468 KB Output is correct
47 Correct 7 ms 468 KB Output is correct
48 Correct 7 ms 596 KB Output is correct
49 Correct 5 ms 340 KB Output is correct
50 Correct 6 ms 468 KB Output is correct
51 Correct 6 ms 480 KB Output is correct
52 Correct 6 ms 476 KB Output is correct
53 Incorrect 1177 ms 16988 KB Output isn't correct
54 Halted 0 ms 0 KB -