답안 #522875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522875 2022-02-06T08:35:43 Z Cross_Ratio Monochrome Points (JOI20_monochrome) C++14
100 / 100
1360 ms 9816 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx2")
using namespace std;
struct SegTree {
    vector<long long int> seg;
    int MAX;
    void init(int N) {
        seg.resize(N+5);
        MAX = N+5;
    }
    void clear() {
        fill(seg.begin(),seg.end(),0);
    }
    long long int sum(int i) {
        long long int ans = 0;
        while(i>0) {
            //cout << i << ' ' << ans << '\n';
            ans += seg[i];
            i -= (i&-i);
        }
        return ans;
    }
    void Edit(int i, long long int a) {
        i++;
        while(i<MAX) {
            //cout << i << '\n';
            seg[i] += a;
            i += (i & -i);
        }
    }
    long long int sum(int s, int e) {
        return sum(e)-sum(s);
    }
};
SegTree tree;
long long int simulate(vector<int> V) {
    //cout << "simul\n";
    tree.clear();
    vector<int> used;
    used.resize(V.size()/2);
    fill(used.begin(),used.end(),-1);
    long long int ans = 0;
    int i;
    for(i=0;i<V.size();i++) {
        if(used[V[i]] != -1) {
            ans += tree.sum(used[V[i]]+1, i);
            tree.Edit(used[V[i]],-1);
        }
        else {
            tree.Edit(i, 1);
            used[V[i]] = i;
        }
    }
    return ans;
}
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N;
    string s2;
    cin >> N >> s2;
    tree.init(2*N);
    int i, j, k;
    vector<int> A, B;
    for(i=0;i<2*N;i++) {
        if(s2[i]=='B') A.push_back(i);
        else B.push_back(i);
    }
    vector<int> V;
    V.resize(s2.length());
    for(i=0;i<A.size();i++) V[A[i]] = i;
    long long int ans = -1;
    int s = 0, e = N - 1;
    while(e-s>=3) {
        int l = (2*s+e)/3;
        int r = (s+2*e)/3;
        for(int j = l; j < l + N; j++) {
            V[B[j%N]] = j-l;
        }
        long long int v1 = simulate(V);
        for(int j = r; j < r + N; j++) {
            V[B[j%N]] = j-r;
        }
        long long int v2 = simulate(V);
        if(v1<v2) s = l;
        else e = r;
    }
    for(i=s;i<=e;i++) {
        for(int j = i; j < i + N; j++) {
            V[B[j%N]] = j-i;
        }
        ans = max(ans, simulate(V));
    }
    cout << ans;
}

Compilation message

monochrome.cpp: In function 'long long int simulate(std::vector<int>)':
monochrome.cpp:47:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(i=0;i<V.size();i++) {
      |             ~^~~~~~~~~
monochrome.cpp: In function 'int main()':
monochrome.cpp:75:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(i=0;i<A.size();i++) V[A[i]] = i;
      |             ~^~~~~~~~~
monochrome.cpp:67:12: warning: unused variable 'j' [-Wunused-variable]
   67 |     int i, j, k;
      |            ^
monochrome.cpp:67:15: warning: unused variable 'k' [-Wunused-variable]
   67 |     int i, j, k;
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 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 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 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 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 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 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 2 ms 204 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 6 ms 332 KB Output is correct
36 Correct 7 ms 332 KB Output is correct
37 Correct 8 ms 460 KB Output is correct
38 Correct 7 ms 332 KB Output is correct
39 Correct 7 ms 332 KB Output is correct
40 Correct 7 ms 404 KB Output is correct
41 Correct 6 ms 332 KB Output is correct
42 Correct 8 ms 412 KB Output is correct
43 Correct 7 ms 332 KB Output is correct
44 Correct 7 ms 332 KB Output is correct
45 Correct 6 ms 332 KB Output is correct
46 Correct 7 ms 404 KB Output is correct
47 Correct 7 ms 332 KB Output is correct
48 Correct 7 ms 404 KB Output is correct
49 Correct 6 ms 332 KB Output is correct
50 Correct 6 ms 408 KB Output is correct
51 Correct 6 ms 332 KB Output is correct
52 Correct 7 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 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 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 2 ms 204 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 6 ms 332 KB Output is correct
36 Correct 7 ms 332 KB Output is correct
37 Correct 8 ms 460 KB Output is correct
38 Correct 7 ms 332 KB Output is correct
39 Correct 7 ms 332 KB Output is correct
40 Correct 7 ms 404 KB Output is correct
41 Correct 6 ms 332 KB Output is correct
42 Correct 8 ms 412 KB Output is correct
43 Correct 7 ms 332 KB Output is correct
44 Correct 7 ms 332 KB Output is correct
45 Correct 6 ms 332 KB Output is correct
46 Correct 7 ms 404 KB Output is correct
47 Correct 7 ms 332 KB Output is correct
48 Correct 7 ms 404 KB Output is correct
49 Correct 6 ms 332 KB Output is correct
50 Correct 6 ms 408 KB Output is correct
51 Correct 6 ms 332 KB Output is correct
52 Correct 7 ms 332 KB Output is correct
53 Correct 1360 ms 9732 KB Output is correct
54 Correct 1350 ms 9624 KB Output is correct
55 Correct 1288 ms 9428 KB Output is correct
56 Correct 1263 ms 9552 KB Output is correct
57 Correct 1255 ms 9552 KB Output is correct
58 Correct 1323 ms 9816 KB Output is correct
59 Correct 1258 ms 9200 KB Output is correct
60 Correct 1290 ms 9556 KB Output is correct
61 Correct 1334 ms 9680 KB Output is correct
62 Correct 1301 ms 9684 KB Output is correct
63 Correct 1284 ms 9676 KB Output is correct
64 Correct 1262 ms 9308 KB Output is correct
65 Correct 1242 ms 9172 KB Output is correct
66 Correct 1277 ms 9192 KB Output is correct
67 Correct 1279 ms 9204 KB Output is correct
68 Correct 1170 ms 8796 KB Output is correct
69 Correct 1337 ms 9656 KB Output is correct
70 Correct 1167 ms 8792 KB Output is correct
71 Correct 1255 ms 9692 KB Output is correct
72 Correct 1236 ms 9692 KB Output is correct
73 Correct 1300 ms 9812 KB Output is correct