Submission #382441

# Submission time Handle Problem Language Result Execution time Memory
382441 2021-03-27T10:44:31 Z BartolM Bigger segments (IZhO19_segments) C++17
100 / 100
121 ms 18952 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const ll MAX=(ll)INF*INF;
const int N=5e5+5;

int n;
ll pref[N], p[N], dp[N];
int lef[N];

void solve() {
    pref[n+1]=MAX;
    lef[0]=0; dp[0]=0;
    for (int i=1; i<=n; ++i) {
        lef[i]=max(lef[i], lef[i-1]);

        dp[i]=dp[lef[i]]+1;
        ll br=2*pref[i]-pref[lef[i]];
        int nx=lower_bound(pref, pref+n+2, br)-pref;
        lef[nx]=i;
    }
    printf("%lld\n", dp[n]);
}

void load() {
    scanf("%d", &n);
    for (int i=1; i<=n; ++i) {
        scanf("%lld", &p[i]);
        pref[i]=pref[i-1]+p[i];
    }
}

int main() {
    load();
    solve();
    return 0;
}

Compilation message

segments.cpp: In function 'void load()':
segments.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
segments.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |         scanf("%lld", &p[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 496 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 496 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 2 ms 492 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 5 ms 492 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 496 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 2 ms 492 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 5 ms 492 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 2 ms 492 KB Output is correct
46 Correct 15 ms 3564 KB Output is correct
47 Correct 17 ms 3628 KB Output is correct
48 Correct 20 ms 3900 KB Output is correct
49 Correct 22 ms 4076 KB Output is correct
50 Correct 23 ms 4076 KB Output is correct
51 Correct 29 ms 4076 KB Output is correct
52 Correct 15 ms 2156 KB Output is correct
53 Correct 10 ms 1516 KB Output is correct
54 Correct 16 ms 3308 KB Output is correct
55 Correct 27 ms 4076 KB Output is correct
56 Correct 18 ms 3564 KB Output is correct
57 Correct 16 ms 3564 KB Output is correct
58 Correct 17 ms 3564 KB Output is correct
59 Correct 24 ms 3692 KB Output is correct
60 Correct 20 ms 3692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 496 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 2 ms 492 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 5 ms 492 KB Output is correct
43 Correct 1 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 2 ms 492 KB Output is correct
46 Correct 15 ms 3564 KB Output is correct
47 Correct 17 ms 3628 KB Output is correct
48 Correct 20 ms 3900 KB Output is correct
49 Correct 22 ms 4076 KB Output is correct
50 Correct 23 ms 4076 KB Output is correct
51 Correct 29 ms 4076 KB Output is correct
52 Correct 15 ms 2156 KB Output is correct
53 Correct 10 ms 1516 KB Output is correct
54 Correct 16 ms 3308 KB Output is correct
55 Correct 27 ms 4076 KB Output is correct
56 Correct 18 ms 3564 KB Output is correct
57 Correct 16 ms 3564 KB Output is correct
58 Correct 17 ms 3564 KB Output is correct
59 Correct 24 ms 3692 KB Output is correct
60 Correct 20 ms 3692 KB Output is correct
61 Correct 65 ms 15980 KB Output is correct
62 Correct 79 ms 15980 KB Output is correct
63 Correct 99 ms 16396 KB Output is correct
64 Correct 108 ms 18596 KB Output is correct
65 Correct 107 ms 18924 KB Output is correct
66 Correct 121 ms 18952 KB Output is correct
67 Correct 90 ms 15212 KB Output is correct
68 Correct 47 ms 7788 KB Output is correct
69 Correct 78 ms 15084 KB Output is correct
70 Correct 111 ms 18900 KB Output is correct
71 Correct 84 ms 15980 KB Output is correct
72 Correct 78 ms 16364 KB Output is correct
73 Correct 87 ms 17004 KB Output is correct
74 Correct 91 ms 17276 KB Output is correct
75 Correct 108 ms 17332 KB Output is correct