Submission #299763

# Submission time Handle Problem Language Result Execution time Memory
299763 2020-09-15T15:11:07 Z dantoh000 Bigger segments (IZhO19_segments) C++14
100 / 100
224 ms 22100 KB
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, int> li;
ii dp[500005];
int n;
ll p[500005];
ll k[500005];
priority_queue<li, vector<li>, greater<li> > pq;
int main(){
    scanf("%d",&n);
    pq.push({0,0});
    ii best = {0,0};
    for (int i = 1; i <= n; i++){
        scanf("%lld",&p[i]);
        p[i]+=p[i-1];
        /*int j;
        for (j = i-1; j >= 0; j--){
            if (p[i] >= k[j]) break;
        }*/

        li last;
        while (pq.size() && pq.top().fi <= p[i]){
            best = max(best,{dp[pq.top().se].fi,pq.top().se});
            last = pq.top(); pq.pop();
        }

        pq.push(last);
        int j = best.se;
        dp[i] = {dp[j].fi+1, j};
        k[i] = 2*p[i]-p[j];
        //printf("%lld: ",2*p[i]-p[j]);
        pq.push({k[i],i});
    }
    printf("%d",dp[n].fi);
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
segments.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |         scanf("%lld",&p[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 288 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 288 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 288 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 28 ms 4328 KB Output is correct
47 Correct 35 ms 3444 KB Output is correct
48 Correct 66 ms 3576 KB Output is correct
49 Correct 28 ms 3968 KB Output is correct
50 Correct 21 ms 3712 KB Output is correct
51 Correct 55 ms 3704 KB Output is correct
52 Correct 19 ms 2048 KB Output is correct
53 Correct 11 ms 1408 KB Output is correct
54 Correct 29 ms 2936 KB Output is correct
55 Correct 37 ms 3636 KB Output is correct
56 Correct 20 ms 3200 KB Output is correct
57 Correct 26 ms 3956 KB Output is correct
58 Correct 25 ms 3704 KB Output is correct
59 Correct 19 ms 3328 KB Output is correct
60 Correct 26 ms 3328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 288 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 28 ms 4328 KB Output is correct
47 Correct 35 ms 3444 KB Output is correct
48 Correct 66 ms 3576 KB Output is correct
49 Correct 28 ms 3968 KB Output is correct
50 Correct 21 ms 3712 KB Output is correct
51 Correct 55 ms 3704 KB Output is correct
52 Correct 19 ms 2048 KB Output is correct
53 Correct 11 ms 1408 KB Output is correct
54 Correct 29 ms 2936 KB Output is correct
55 Correct 37 ms 3636 KB Output is correct
56 Correct 20 ms 3200 KB Output is correct
57 Correct 26 ms 3956 KB Output is correct
58 Correct 25 ms 3704 KB Output is correct
59 Correct 19 ms 3328 KB Output is correct
60 Correct 26 ms 3328 KB Output is correct
61 Correct 146 ms 22100 KB Output is correct
62 Correct 191 ms 18080 KB Output is correct
63 Correct 188 ms 16048 KB Output is correct
64 Correct 144 ms 16632 KB Output is correct
65 Correct 122 ms 16888 KB Output is correct
66 Correct 224 ms 16888 KB Output is correct
67 Correct 165 ms 13720 KB Output is correct
68 Correct 78 ms 7032 KB Output is correct
69 Correct 151 ms 13176 KB Output is correct
70 Correct 176 ms 17016 KB Output is correct
71 Correct 94 ms 14048 KB Output is correct
72 Correct 190 ms 17884 KB Output is correct
73 Correct 112 ms 16356 KB Output is correct
74 Correct 97 ms 15352 KB Output is correct
75 Correct 131 ms 15352 KB Output is correct