Submission #807844

# Submission time Handle Problem Language Result Execution time Memory
807844 2023-08-05T03:04:44 Z nonono Hacker (BOI15_hac) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1e6 + 5;

int n, m;
int a[mxN];
int b[mxN];

int main() {
    #define taskname ""

    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin.tie(0)->sync_with_stdio(0);

    cin >> n;
    
    for(int i = 1; i <= n; i ++) {
        cin >> a[i];
        a[n + i] = a[i];
    }
    
    m = (n + 1) / 2;
    
    for(int i = 1; i <= 2 * n; i ++) {
        b[i] += b[i - 1] + a[i];
        if(i > m) b[i] -= a[i - m];
    }
    
    deque<int> dq;
    
    int result = 0;
    for(int i = m; i <= 2 * n; i ++) {
        while(!dq.empty() && i - dq.front() > m) dq.pop_front();
        while(!dq.empty() && b[dq.back()] >= b[i]) dq.pop_back();
        dq.push_back(i);
        if(i >= 2 * m - 1) result = max(result, b[dq.front()]);
    }
    
    cout << result << "\n";
    return 0;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -