Submission #772328

# Submission time Handle Problem Language Result Execution time Memory
772328 2023-07-04T03:39:07 Z SLin25 Hacker (BOI15_hac) C++14
100 / 100
43 ms 10628 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    int arr[n];
    int pref[n+1]{};
    int k = (n + 1) / 2;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    for (int i = 1; i <= n; i++) {
        pref[i] += pref[i-1] + arr[i-1];
    }
    int val[n]; //segment ending at index
    for (int i = 0; i < n; i++) {
        int prev = i - k + 1;
        int tmp = 0;
        if (prev < 0) {
            tmp = pref[i+1] + pref[n] - pref[n + prev];
        } else {
            tmp = pref[i+1] - pref[prev];
        }
        val[i] = tmp;
    }
    deque<pair<int, int>> q;
    int ans = 0;
    for (int i = 0; i < k; i++) {
        while (!q.empty() && q.back().first > val[i]) {
            q.pop_back();
        }
        q.push_back({val[i], i});
    }

    ans = max(ans, q.front().first);

    for (int i = k; i < n; i++) {
        while (!q.empty() && q.back().first > val[i]) {
            q.pop_back();
        }
        q.push_back({val[i], i});
        if (q.front().second == i - k) q.pop_front();
        ans = max(ans, q.front().first);
    }
    for (int i = 0; i < k; i++) {
        while (!q.empty() && q.back().first > val[i]) {
            q.pop_back();
        }
        q.push_back({val[i], i});
        if (q.front().second == i - k + n) q.pop_front();
        ans = max(ans, q.front().first);
    }

    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 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 316 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 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 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 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 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 316 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 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 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 316 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 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 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 7 ms 1236 KB Output is correct
5 Correct 20 ms 2648 KB Output is correct
6 Correct 22 ms 3256 KB Output is correct
7 Correct 26 ms 3812 KB Output is correct
8 Correct 43 ms 6172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 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 316 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 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 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 316 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 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 1 ms 340 KB Output is correct
31 Correct 1 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 1 ms 340 KB Output is correct
35 Correct 7 ms 1236 KB Output is correct
36 Correct 20 ms 2648 KB Output is correct
37 Correct 22 ms 3256 KB Output is correct
38 Correct 26 ms 3812 KB Output is correct
39 Correct 43 ms 6172 KB Output is correct
40 Correct 2 ms 464 KB Output is correct
41 Correct 2 ms 596 KB Output is correct
42 Correct 3 ms 696 KB Output is correct
43 Correct 17 ms 3472 KB Output is correct
44 Correct 42 ms 8268 KB Output is correct
45 Correct 9 ms 1740 KB Output is correct
46 Correct 25 ms 5076 KB Output is correct
47 Correct 42 ms 8304 KB Output is correct
48 Correct 37 ms 10628 KB Output is correct
49 Correct 42 ms 9712 KB Output is correct
50 Correct 38 ms 9712 KB Output is correct