Submission #917437

# Submission time Handle Problem Language Result Execution time Memory
917437 2024-01-28T07:56:08 Z theghostking Hacker (BOI15_hac) C++17
100 / 100
105 ms 14024 KB
#include <bits/stdc++.h>
using namespace std;

deque<int> q;

void ins(int x){
    while (!q.empty() && q.back() > x){
        q.pop_back();
    }
    q.push_back(x);
}

void ers(int x){
    if (!q.empty() && q.front() == x){
        q.pop_front();
    }
}

int getmn(){
    return q.front();
}

int main() {
    int n;
    cin >> n;
    vector<int> a(2*n);
    for (int i = 0; i<n; i++){
        cin >> a[i];
        a[n+i] = a[i];
    }
    vector<int> res;
    int k = (n+1)/2;
    int sm = 0;
    for (int i = 0; i<k; i++){
        sm += a[i];
    }
    res.push_back(sm);
    for (int i = k; i<n+k-1; i++){
        sm -= a[i-k];
        sm += a[i];
        res.push_back(sm);
    }
    for (int i = 0; i<n; i++){
        res.push_back(res[i]);
    }
    vector<int> ans(n, 1e9);
    for (int i = 0; i<k; i++){
        ins(res[i]);
    }
    ans[k-1] = getmn();
    for (int i = k; i<2*n; i++){
        ers(res[i-k]);
        ins(res[i]);
        int ind = i; if (ind >= n) ind -= n;
        ans[ind] = getmn();
    }
    int mx = 0;
    for (auto u : ans){
        mx = max(mx,u);
    }
    cout << mx << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 532 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 17 ms 2540 KB Output is correct
5 Correct 46 ms 5044 KB Output is correct
6 Correct 51 ms 6340 KB Output is correct
7 Correct 73 ms 9664 KB Output is correct
8 Correct 102 ms 12332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 436 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 532 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 17 ms 2540 KB Output is correct
36 Correct 46 ms 5044 KB Output is correct
37 Correct 51 ms 6340 KB Output is correct
38 Correct 73 ms 9664 KB Output is correct
39 Correct 102 ms 12332 KB Output is correct
40 Correct 2 ms 600 KB Output is correct
41 Correct 4 ms 860 KB Output is correct
42 Correct 7 ms 1156 KB Output is correct
43 Correct 42 ms 5060 KB Output is correct
44 Correct 103 ms 12408 KB Output is correct
45 Correct 19 ms 2512 KB Output is correct
46 Correct 61 ms 8388 KB Output is correct
47 Correct 102 ms 12380 KB Output is correct
48 Correct 105 ms 14024 KB Output is correct
49 Correct 83 ms 12752 KB Output is correct
50 Correct 83 ms 12732 KB Output is correct