답안 #823276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823276 2023-08-12T10:20:36 Z serifefedartar Hacker (BOI15_hac) C++17
20 / 100
145 ms 8356 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000009
#define LOGN 20
#define MAXN 500005


int n;
int sg[4*MAXN];
vector<int> v, pref;
int get_sum(int begin, int len) {
    if (begin + len - 1 <= n)
        return pref[begin + len - 1] - pref[begin - 1];
    else
        return pref[n] - pref[begin - 1] + pref[len - n + begin - 1];
}

void init(int k, int a, int b) {
    if (a == b) {
        sg[k] = get_sum(a, n/2);
        return ; 
    }
    init(2*k, a, (a+b)/2);
    init(2*k+1, (a+b)/2+1, b);
    sg[k] = max(sg[2*k], sg[2*k+1]);
}

int query(int k, int a, int b, int q_l, int q_r) {
    if (a > q_r || b < q_l)
        return 0;
    if (q_l <= a && b <= q_r)
        return sg[k];
    return max(query(2*k, a, (a+b)/2, q_l, q_r), query(2*k+1, (a+b)/2+1, b, q_l, q_r));
}

int main() {
    fast
    cin >> n;

    v = vector<int>(n+1);
    pref = vector<int>(n+1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
        pref[i] = pref[i-1] + v[i]; 
    }
    init(1, 1, n);

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int max_protect;
        if (i + 1 + n/2 <= n)
            max_protect = query(1, 1, n, i + 1, i + n/2);
        else
            max_protect = max(query(1, 1, n, i + 1, n), query(1, 1, n, 1, 1 + i + n/2 - n));
        ans = max(ans, pref[n] - max_protect);
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 22 ms 1876 KB Output is correct
5 Correct 54 ms 3924 KB Output is correct
6 Correct 69 ms 4336 KB Output is correct
7 Correct 86 ms 6648 KB Output is correct
8 Correct 145 ms 8356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -