Submission #630117

# Submission time Handle Problem Language Result Execution time Memory
630117 2022-08-15T17:24:46 Z Neos Hacker (BOI15_hac) C++14
100 / 100
326 ms 20300 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using ii = pair<ll, ll>;

#define fastIO ios::sync_with_stdio(0); cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define numBit(x) (__builtin_popcountll(1ll * (x)))
#define getBit(x, i) ((x) >> (i) & 1)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        X eps = 1e-9;
        if (x > y + eps) {
            x = y;
            return true;
        } else return false;
    }
template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        X eps = 1e-9;
        if (x + eps < y) {
            x = y;
            return true;
        } else return false;
    }

const int N = 1e6 + 7, oo = 1e9 + 7;

int n, a[N];

signed main() {
    fastIO;
    if (fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], a[i + n] = a[i];
    for (int i = 1; i <= 2 * n; i++) a[i] += a[i - 1];

    vector<int> ret(n + 1, oo);
    multiset<int> val; int len = n + 1 >> 1;
    for (int i = 1; i <= 2 * n; i++) {
        if (i + len - 1 <= 2 * n) val.insert(a[i + len - 1] - a[i - 1]);
        if (i > len) val.erase(val.find(a[i - 1] - a[i - 1 - len]));

        int prv = (i - 1) % n + 1;
        minimize(ret[prv], *val.begin());
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) maximize(ans, ret[i]);
    cout << ans;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:51:36: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |     multiset<int> val; int len = n + 1 >> 1;
      |                                  ~~^~~
hac.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 0 ms 220 KB Output is correct
28 Correct 0 ms 220 KB Output is correct
29 Correct 0 ms 220 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 2 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 220 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 476 KB Output is correct
4 Correct 33 ms 3164 KB Output is correct
5 Correct 97 ms 7276 KB Output is correct
6 Correct 148 ms 9040 KB Output is correct
7 Correct 144 ms 11060 KB Output is correct
8 Correct 326 ms 20080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 0 ms 220 KB Output is correct
28 Correct 0 ms 220 KB Output is correct
29 Correct 0 ms 220 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 2 ms 476 KB Output is correct
32 Correct 0 ms 220 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 476 KB Output is correct
35 Correct 33 ms 3164 KB Output is correct
36 Correct 97 ms 7276 KB Output is correct
37 Correct 148 ms 9040 KB Output is correct
38 Correct 144 ms 11060 KB Output is correct
39 Correct 326 ms 20080 KB Output is correct
40 Correct 4 ms 612 KB Output is correct
41 Correct 9 ms 1116 KB Output is correct
42 Correct 12 ms 1532 KB Output is correct
43 Correct 98 ms 8148 KB Output is correct
44 Correct 282 ms 20032 KB Output is correct
45 Correct 42 ms 4180 KB Output is correct
46 Correct 162 ms 12132 KB Output is correct
47 Correct 314 ms 20088 KB Output is correct
48 Correct 235 ms 20300 KB Output is correct
49 Correct 207 ms 19500 KB Output is correct
50 Correct 212 ms 19404 KB Output is correct