Submission #167367

# Submission time Handle Problem Language Result Execution time Memory
167367 2019-12-07T17:41:59 Z theboatman Bigger segments (IZhO19_segments) C++17
100 / 100
118 ms 25792 KB
#include <bits/stdc++.h>

#define fi first
#define se second

#define y1 theboatman

using namespace std;
typedef long long ll;

const int N = int(1e6) + 10;
const int inf = int(1e9) + 10;
const long long INF = ll(1e18) + 10;

vector <ll> pref;

ll get(int l, int r) {
    return pref[r] - (l ? pref[l - 1] : 0);
}

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

    int n;
    cin >> n;

    vector <int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    pref.resize(n);
    for(int i = 0; i < n; i++) {
        pref[i] = (i ? pref[i - 1] + a[i] : a[i]);
    }

    vector <pair <ll, int> > dp(n);
    for(int i = 0; i < n; i++) {
        dp[i] = {get(0, i), 1};
    }

    vector <pair <ll, int> > lazy(n, {INF, inf});

    pair <ll, int> now = {0LL, -1};
    for(int i = 0; i < n; i++) {
        now.fi += a[i];
        now = min(now, lazy[i]);

        dp[i] = min(dp[i], now);
        if (i + 1 == n || get(i + 1, n - 1) < now.fi) {
            continue;
        }

        int l = i + 1, r = n - 1;
        while(l < r) {
            int c = l + r >> 1;

            if (get(i + 1, c) < now.fi) {
                l = c + 1;
            }
            else {
                r = c;
            }
        }

        lazy[l] = min(lazy[l], {get(i + 1, l), now.se - 1});
    }

    cout << -dp[n - 1].se << "\n";
    return 0;
}
/*
*/

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:57:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int c = l + r >> 1;
                     ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 452 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 412 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 452 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 412 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 476 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 508 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 3 ms 508 KB Output is correct
43 Correct 3 ms 508 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 452 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 412 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 476 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 508 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 3 ms 508 KB Output is correct
43 Correct 3 ms 508 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 4 ms 504 KB Output is correct
46 Correct 15 ms 5112 KB Output is correct
47 Correct 21 ms 5112 KB Output is correct
48 Correct 23 ms 5496 KB Output is correct
49 Correct 23 ms 5624 KB Output is correct
50 Correct 23 ms 5676 KB Output is correct
51 Correct 25 ms 5624 KB Output is correct
52 Correct 14 ms 2936 KB Output is correct
53 Correct 10 ms 1884 KB Output is correct
54 Correct 19 ms 4856 KB Output is correct
55 Correct 24 ms 5624 KB Output is correct
56 Correct 18 ms 5112 KB Output is correct
57 Correct 18 ms 5116 KB Output is correct
58 Correct 19 ms 5112 KB Output is correct
59 Correct 19 ms 5240 KB Output is correct
60 Correct 19 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 452 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 412 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 476 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 508 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 3 ms 508 KB Output is correct
43 Correct 3 ms 508 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 4 ms 504 KB Output is correct
46 Correct 15 ms 5112 KB Output is correct
47 Correct 21 ms 5112 KB Output is correct
48 Correct 23 ms 5496 KB Output is correct
49 Correct 23 ms 5624 KB Output is correct
50 Correct 23 ms 5676 KB Output is correct
51 Correct 25 ms 5624 KB Output is correct
52 Correct 14 ms 2936 KB Output is correct
53 Correct 10 ms 1884 KB Output is correct
54 Correct 19 ms 4856 KB Output is correct
55 Correct 24 ms 5624 KB Output is correct
56 Correct 18 ms 5112 KB Output is correct
57 Correct 18 ms 5116 KB Output is correct
58 Correct 19 ms 5112 KB Output is correct
59 Correct 19 ms 5240 KB Output is correct
60 Correct 19 ms 5240 KB Output is correct
61 Correct 68 ms 23840 KB Output is correct
62 Correct 94 ms 23836 KB Output is correct
63 Correct 100 ms 24184 KB Output is correct
64 Correct 111 ms 25792 KB Output is correct
65 Correct 115 ms 25596 KB Output is correct
66 Correct 118 ms 25592 KB Output is correct
67 Correct 98 ms 21496 KB Output is correct
68 Correct 64 ms 10888 KB Output is correct
69 Correct 85 ms 23032 KB Output is correct
70 Correct 114 ms 25720 KB Output is correct
71 Correct 82 ms 23800 KB Output is correct
72 Correct 92 ms 24184 KB Output is correct
73 Correct 106 ms 24952 KB Output is correct
74 Correct 96 ms 25208 KB Output is correct
75 Correct 96 ms 25208 KB Output is correct