Submission #739104

# Submission time Handle Problem Language Result Execution time Memory
739104 2023-05-10T00:25:40 Z Charizard2021 Hacker (BOI15_hac) C++17
100 / 100
74 ms 10684 KB
#include <cstdio>
#include <deque>
#include <algorithm>
using namespace std;

int a[500005], n;

int f(int s, int e){
    if(s <= 0){
        return a[e] + (a[n] - a[s+n-1]);
    }
    return a[e] - a[s-1];
}

int px[500005], qx[500005];
deque<int> dq, num;

int main(){
    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%d",&a[i]);
        a[i] += a[i-1];
    }
    for (int i=1; i<=n; i++) {
        px[i-1] = f(i - (n-1) / 2,i);
    }
    for (int i=0; i<n+(n-1)/2; i++) {
        if(!num.empty() && num.front() == i - (n+1)/2){
            num.pop_front();
            dq.pop_front();
        }
        while (!dq.empty() && dq.back() > px[i%n]) {
            num.pop_back();
            dq.pop_back();
        }
        dq.push_back(px[i%n]);
        num.push_back(i);
        if(i - (n-1)/2 >= 0){
            qx[i - (n-1)/2] = dq.front();
        }
    }
    printf("%d",*max_element(qx,qx+n));
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
hac.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
# 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 0 ms 300 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 296 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 0 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 212 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 0 ms 300 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 296 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 0 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 296 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 1 ms 340 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 296 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 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 14 ms 1580 KB Output is correct
5 Correct 31 ms 3348 KB Output is correct
6 Correct 42 ms 4288 KB Output is correct
7 Correct 47 ms 5096 KB Output is correct
8 Correct 74 ms 8296 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 0 ms 300 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 296 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 0 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 296 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 1 ms 340 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 296 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 300 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 14 ms 1580 KB Output is correct
36 Correct 31 ms 3348 KB Output is correct
37 Correct 42 ms 4288 KB Output is correct
38 Correct 47 ms 5096 KB Output is correct
39 Correct 74 ms 8296 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 4 ms 564 KB Output is correct
42 Correct 5 ms 700 KB Output is correct
43 Correct 33 ms 3460 KB Output is correct
44 Correct 71 ms 8208 KB Output is correct
45 Correct 13 ms 1820 KB Output is correct
46 Correct 44 ms 5068 KB Output is correct
47 Correct 74 ms 8336 KB Output is correct
48 Correct 73 ms 10684 KB Output is correct
49 Correct 63 ms 9744 KB Output is correct
50 Correct 59 ms 9776 KB Output is correct