답안 #723588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723588 2023-04-14T05:52:53 Z MDSPro Hacker (BOI15_hac) C++17
100 / 100
226 ms 8808 KB
#include "bits/stdc++.h"

using namespace std;
const int MAXN = 3e6;
const int INF = 1e9;

int n,N;
vector<int> tr;
void build(int n){
    N = (1<<(32-__builtin_clz(n)));
    tr.assign(2*N,INF);
}

void upd(int l, int r, int val){
    if(l >= n) upd(l-n,r-n,val);
    else if(r > n) {
        upd(l,n,val);
        upd(0,r-n,val);
    } else {
        for(l += N, r += N; l < r; l >>= 1, r >>= 1){
            if(l&1) {
                tr[l] = min(tr[l],val);
                l++;
            }

            if(r&1) {
                --r;
                tr[r] = min(tr[r],val);
            }
        }
    }
}

int get(int idx){
    int ans = INF;
    for(idx += N; idx > 0; idx >>= 1) ans = min(tr[idx],ans);
    return ans;
}

int main(){
    cin >> n;
    vector<int> v(2*n);
    for(int i = 0,x; i < n; ++i){
        cin >> x;
        v[i] = v[i+n] = x;
    }
    
    build(n);
    
    int sum = 0;
    int need = (n+1)/2;
    for(int i = 0; i < 2*n; ++i){
        sum += v[i];
        if(i-need+1 >= 0) {
            upd(i-need+1,i+1,sum);
            sum -= v[i-need+1];
        }
    }

    int res = 0;
    for(int i = 0; i < n; ++i) res = max(res,get(i));
    cout << res;
}
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 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 2 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 29 ms 1968 KB Output is correct
5 Correct 73 ms 3908 KB Output is correct
6 Correct 97 ms 4308 KB Output is correct
7 Correct 122 ms 6744 KB Output is correct
8 Correct 226 ms 8304 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 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 2 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 29 ms 1968 KB Output is correct
36 Correct 73 ms 3908 KB Output is correct
37 Correct 97 ms 4308 KB Output is correct
38 Correct 122 ms 6744 KB Output is correct
39 Correct 226 ms 8304 KB Output is correct
40 Correct 4 ms 468 KB Output is correct
41 Correct 7 ms 804 KB Output is correct
42 Correct 11 ms 852 KB Output is correct
43 Correct 73 ms 4292 KB Output is correct
44 Correct 190 ms 8576 KB Output is correct
45 Correct 33 ms 2388 KB Output is correct
46 Correct 131 ms 7052 KB Output is correct
47 Correct 186 ms 8752 KB Output is correct
48 Correct 190 ms 8808 KB Output is correct
49 Correct 172 ms 8652 KB Output is correct
50 Correct 163 ms 8596 KB Output is correct