Submission #628453

# Submission time Handle Problem Language Result Execution time Memory
628453 2022-08-13T12:05:45 Z MohamedFaresNebili Monochrome Points (JOI20_monochrome) C++14
100 / 100
1353 ms 23508 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
            #define int ll

            int N, ST[800005]; 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;
            }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 256 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 256 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 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 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 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 2 ms 340 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 256 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 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 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 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 2 ms 340 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 368 KB Output is correct
34 Correct 8 ms 596 KB Output is correct
35 Correct 8 ms 552 KB Output is correct
36 Correct 7 ms 472 KB Output is correct
37 Correct 7 ms 472 KB Output is correct
38 Correct 7 ms 468 KB Output is correct
39 Correct 6 ms 468 KB Output is correct
40 Correct 7 ms 468 KB Output is correct
41 Correct 6 ms 544 KB Output is correct
42 Correct 9 ms 476 KB Output is correct
43 Correct 8 ms 476 KB Output is correct
44 Correct 8 ms 476 KB Output is correct
45 Correct 8 ms 540 KB Output is correct
46 Correct 6 ms 476 KB Output is correct
47 Correct 7 ms 476 KB Output is correct
48 Correct 8 ms 476 KB Output is correct
49 Correct 6 ms 476 KB Output is correct
50 Correct 7 ms 468 KB Output is correct
51 Correct 6 ms 476 KB Output is correct
52 Correct 7 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 256 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 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 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 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 2 ms 340 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 368 KB Output is correct
34 Correct 8 ms 596 KB Output is correct
35 Correct 8 ms 552 KB Output is correct
36 Correct 7 ms 472 KB Output is correct
37 Correct 7 ms 472 KB Output is correct
38 Correct 7 ms 468 KB Output is correct
39 Correct 6 ms 468 KB Output is correct
40 Correct 7 ms 468 KB Output is correct
41 Correct 6 ms 544 KB Output is correct
42 Correct 9 ms 476 KB Output is correct
43 Correct 8 ms 476 KB Output is correct
44 Correct 8 ms 476 KB Output is correct
45 Correct 8 ms 540 KB Output is correct
46 Correct 6 ms 476 KB Output is correct
47 Correct 7 ms 476 KB Output is correct
48 Correct 8 ms 476 KB Output is correct
49 Correct 6 ms 476 KB Output is correct
50 Correct 7 ms 468 KB Output is correct
51 Correct 6 ms 476 KB Output is correct
52 Correct 7 ms 476 KB Output is correct
53 Correct 1353 ms 23012 KB Output is correct
54 Correct 1327 ms 23508 KB Output is correct
55 Correct 1286 ms 22680 KB Output is correct
56 Correct 1248 ms 22684 KB Output is correct
57 Correct 1268 ms 22968 KB Output is correct
58 Correct 1187 ms 23328 KB Output is correct
59 Correct 1174 ms 22688 KB Output is correct
60 Correct 1179 ms 22824 KB Output is correct
61 Correct 1210 ms 22936 KB Output is correct
62 Correct 1277 ms 22960 KB Output is correct
63 Correct 1288 ms 22940 KB Output is correct
64 Correct 1239 ms 22912 KB Output is correct
65 Correct 1086 ms 22496 KB Output is correct
66 Correct 1174 ms 22468 KB Output is correct
67 Correct 1249 ms 22724 KB Output is correct
68 Correct 1133 ms 22204 KB Output is correct
69 Correct 1242 ms 23080 KB Output is correct
70 Correct 1132 ms 22304 KB Output is correct
71 Correct 1241 ms 23384 KB Output is correct
72 Correct 1189 ms 23272 KB Output is correct
73 Correct 1294 ms 23420 KB Output is correct