Submission #897863

# Submission time Handle Problem Language Result Execution time Memory
897863 2024-01-03T21:49:16 Z asdasdqwer Hacker (BOI15_hac) C++14
100 / 100
53 ms 13836 KB
#include <bits/stdc++.h>
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;cin>>n;
    vector<int> a(n);
    for (int &x:a)cin>>x;

    for (int i=0;i<n;i++) {
        a.push_back(a[i]);
    }

    int windowLength = n/2;
    if (n%2!=0)windowLength++;

    int sm1=0;
    for (int i=0;i<windowLength;i++) {
        sm1+=a[i];
    }

    vector<int> ans(a.size(), 1e9);
    typedef array<int,2> pii;
    deque<pii> dq;
    ans[0]=sm1;
    dq.push_back({sm1, windowLength-1});
    for (int i=1;i<=a.size()-windowLength;i++) {
        int ot = i + windowLength - 1;
        sm1 += a[ot] - a[i-1];

        while (dq.size() && dq.back()[0] >= sm1) dq.pop_back();

        dq.push_back({sm1, ot});

        ans[i] = dq.front()[0];

        if (dq.front()[1] == i) {
            dq.pop_front();
        }
    }

    vector<int> ans2(n);
    for (int i=0;i<n;i++) {
        ans2[i]=ans[i];
        if (i+n<ans.size()) {
            ans2[i]=min(ans2[i], ans[i+n]);
        }
    }

    int mx=0;
    for (int i=0;i<n;i++) {
        mx=max(mx, ans2[i]);
    }

    cout<<mx<<"\n";
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i=1;i<=a.size()-windowLength;i++) {
      |                  ~^~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:47:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         if (i+n<ans.size()) {
      |             ~~~^~~~~~~~~~~
# 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 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 460 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 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 460 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 476 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 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 9 ms 2332 KB Output is correct
5 Correct 17 ms 4928 KB Output is correct
6 Correct 23 ms 6280 KB Output is correct
7 Correct 27 ms 7624 KB Output is correct
8 Correct 53 ms 12208 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 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 460 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 476 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 9 ms 2332 KB Output is correct
36 Correct 17 ms 4928 KB Output is correct
37 Correct 23 ms 6280 KB Output is correct
38 Correct 27 ms 7624 KB Output is correct
39 Correct 53 ms 12208 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 856 KB Output is correct
42 Correct 3 ms 1116 KB Output is correct
43 Correct 18 ms 5196 KB Output is correct
44 Correct 44 ms 12356 KB Output is correct
45 Correct 9 ms 2772 KB Output is correct
46 Correct 29 ms 7640 KB Output is correct
47 Correct 44 ms 12352 KB Output is correct
48 Correct 39 ms 12460 KB Output is correct
49 Correct 40 ms 13836 KB Output is correct
50 Correct 36 ms 13740 KB Output is correct