답안 #703863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703863 2023-02-28T18:13:31 Z _martynas Hacker (BOI15_hac) C++11
100 / 100
112 ms 34128 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

#define F first
#define S second
#define PB push_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

void FASTIO() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

const int MXN = 5e5+5;

int n;
ll A[2*MXN], pref[2*MXN];

int par[2*MXN], sz[2*MXN];
void init_dsu() {
    iota(par, par+2*n, 0);
    fill(sz, sz+2*n, 1);
}

int find_set(int a) {
    return par[a] == a ? a : par[a] = find_set(par[a]);
}

void unite(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if(a == b) return;
    if(sz[a] < sz[b]) swap(a, b);
    sz[a] += sz[b];
    par[b] = a;
}

int main() {
    FASTIO();
    cin >> n;
    for(int i = 0; i < n; i++) cin >> A[i], A[i+n] = A[i];
    pref[0] = A[0];
    for(int i = 1; i < 2*n; i++) pref[i] = pref[i-1]+A[i];
    vector<pli> B;
    for(int i = 0; i < n; i++) {
        B.PB({pref[i+(n+1)/2-1]-(i?pref[i-1]:0), (i+(n+1)/2)%n});
    }
    sort(rall(B));
    vector<bool> active(2*n);
    auto activate = [&](int i) {
        active[i] = true;
        if(i && active[i-1]) {
            unite(i, i-1);
        }
        if(i+1<2*n && active[i+1]) {
            unite(i, i+1);
        }
        return sz[find_set(i)];
    };
    init_dsu();
    for(auto p : B) {
        int res = 0;
        res = max(activate(p.S), activate(p.S+n));
        if(res >= (n+1)/2) {
            cout << p.F << "\n";
            return 0;
        }
    }
    return 0;
}

/*



*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 328 KB Output is correct
15 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 328 KB Output is correct
15 Correct 0 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 0 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 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 0 ms 328 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 16 ms 5832 KB Output is correct
5 Correct 39 ms 13720 KB Output is correct
6 Correct 47 ms 17160 KB Output is correct
7 Correct 61 ms 20612 KB Output is correct
8 Correct 112 ms 33836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 328 KB Output is correct
15 Correct 0 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 0 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 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 0 ms 328 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 724 KB Output is correct
35 Correct 16 ms 5832 KB Output is correct
36 Correct 39 ms 13720 KB Output is correct
37 Correct 47 ms 17160 KB Output is correct
38 Correct 61 ms 20612 KB Output is correct
39 Correct 112 ms 33836 KB Output is correct
40 Correct 2 ms 1112 KB Output is correct
41 Correct 5 ms 1748 KB Output is correct
42 Correct 6 ms 2500 KB Output is correct
43 Correct 41 ms 13776 KB Output is correct
44 Correct 101 ms 33928 KB Output is correct
45 Correct 20 ms 6988 KB Output is correct
46 Correct 61 ms 20552 KB Output is correct
47 Correct 105 ms 33868 KB Output is correct
48 Correct 111 ms 34128 KB Output is correct
49 Correct 101 ms 33328 KB Output is correct
50 Correct 98 ms 33336 KB Output is correct