Submission #486854

# Submission time Handle Problem Language Result Execution time Memory
486854 2021-11-13T01:42:31 Z SirCovidThe19th Bigger segments (IZhO19_segments) C++17
100 / 100
273 ms 44216 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second

const int mx = 5e5 + 5;

int n; ll pre[mx]; vector<int> ok[mx]; pair<int, ll> bst, dp[mx]; 

int main(){
    int n; cin >> n; 
    for (int i = 1; i <= n; i++) cin >> pre[i], pre[i] += pre[i - 1];
    ok[1].push_back(0);
    for (int i = 1, l = 0; i <= n; i++){
        for (int X : ok[i]) bst = max(bst, {dp[X].f + 1, X});
        dp[i] = {bst.f, pre[i] - pre[bst.s]};    
        int okPos = lower_bound(pre + 1, pre + n + 1, pre[i] + dp[i].s) - pre;
        ok[okPos].push_back(i);
    }
    cout<<dp[n].f<<endl;
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:16:21: warning: unused variable 'l' [-Wunused-variable]
   16 |     for (int i = 1, l = 0; i <= n; i++){
      |                     ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 6 ms 11964 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 8 ms 12056 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 7 ms 12020 KB Output is correct
8 Correct 8 ms 11980 KB Output is correct
9 Correct 7 ms 11980 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 11980 KB Output is correct
13 Correct 6 ms 12056 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 6 ms 11980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 6 ms 11964 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 8 ms 12056 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 7 ms 12020 KB Output is correct
8 Correct 8 ms 11980 KB Output is correct
9 Correct 7 ms 11980 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 11980 KB Output is correct
13 Correct 6 ms 12056 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 6 ms 11980 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 6 ms 12008 KB Output is correct
18 Correct 8 ms 12056 KB Output is correct
19 Correct 6 ms 11980 KB Output is correct
20 Correct 7 ms 12004 KB Output is correct
21 Correct 7 ms 11980 KB Output is correct
22 Correct 8 ms 12052 KB Output is correct
23 Correct 7 ms 11980 KB Output is correct
24 Correct 9 ms 12056 KB Output is correct
25 Correct 8 ms 11980 KB Output is correct
26 Correct 6 ms 12084 KB Output is correct
27 Correct 7 ms 12024 KB Output is correct
28 Correct 7 ms 12052 KB Output is correct
29 Correct 6 ms 11980 KB Output is correct
30 Correct 7 ms 12056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 6 ms 11964 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 8 ms 12056 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 7 ms 12020 KB Output is correct
8 Correct 8 ms 11980 KB Output is correct
9 Correct 7 ms 11980 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 11980 KB Output is correct
13 Correct 6 ms 12056 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 6 ms 11980 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 6 ms 12008 KB Output is correct
18 Correct 8 ms 12056 KB Output is correct
19 Correct 6 ms 11980 KB Output is correct
20 Correct 7 ms 12004 KB Output is correct
21 Correct 7 ms 11980 KB Output is correct
22 Correct 8 ms 12052 KB Output is correct
23 Correct 7 ms 11980 KB Output is correct
24 Correct 9 ms 12056 KB Output is correct
25 Correct 8 ms 11980 KB Output is correct
26 Correct 6 ms 12084 KB Output is correct
27 Correct 7 ms 12024 KB Output is correct
28 Correct 7 ms 12052 KB Output is correct
29 Correct 6 ms 11980 KB Output is correct
30 Correct 7 ms 12056 KB Output is correct
31 Correct 7 ms 12108 KB Output is correct
32 Correct 8 ms 12092 KB Output is correct
33 Correct 8 ms 12184 KB Output is correct
34 Correct 8 ms 12108 KB Output is correct
35 Correct 8 ms 12236 KB Output is correct
36 Correct 8 ms 12108 KB Output is correct
37 Correct 8 ms 12108 KB Output is correct
38 Correct 9 ms 12108 KB Output is correct
39 Correct 8 ms 12108 KB Output is correct
40 Correct 8 ms 12108 KB Output is correct
41 Correct 7 ms 12108 KB Output is correct
42 Correct 8 ms 12112 KB Output is correct
43 Correct 8 ms 12192 KB Output is correct
44 Correct 7 ms 12236 KB Output is correct
45 Correct 7 ms 12236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 6 ms 11964 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 8 ms 12056 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 7 ms 12020 KB Output is correct
8 Correct 8 ms 11980 KB Output is correct
9 Correct 7 ms 11980 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 11980 KB Output is correct
13 Correct 6 ms 12056 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 6 ms 11980 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 6 ms 12008 KB Output is correct
18 Correct 8 ms 12056 KB Output is correct
19 Correct 6 ms 11980 KB Output is correct
20 Correct 7 ms 12004 KB Output is correct
21 Correct 7 ms 11980 KB Output is correct
22 Correct 8 ms 12052 KB Output is correct
23 Correct 7 ms 11980 KB Output is correct
24 Correct 9 ms 12056 KB Output is correct
25 Correct 8 ms 11980 KB Output is correct
26 Correct 6 ms 12084 KB Output is correct
27 Correct 7 ms 12024 KB Output is correct
28 Correct 7 ms 12052 KB Output is correct
29 Correct 6 ms 11980 KB Output is correct
30 Correct 7 ms 12056 KB Output is correct
31 Correct 7 ms 12108 KB Output is correct
32 Correct 8 ms 12092 KB Output is correct
33 Correct 8 ms 12184 KB Output is correct
34 Correct 8 ms 12108 KB Output is correct
35 Correct 8 ms 12236 KB Output is correct
36 Correct 8 ms 12108 KB Output is correct
37 Correct 8 ms 12108 KB Output is correct
38 Correct 9 ms 12108 KB Output is correct
39 Correct 8 ms 12108 KB Output is correct
40 Correct 8 ms 12108 KB Output is correct
41 Correct 7 ms 12108 KB Output is correct
42 Correct 8 ms 12112 KB Output is correct
43 Correct 8 ms 12192 KB Output is correct
44 Correct 7 ms 12236 KB Output is correct
45 Correct 7 ms 12236 KB Output is correct
46 Correct 30 ms 15248 KB Output is correct
47 Correct 48 ms 16324 KB Output is correct
48 Correct 52 ms 16868 KB Output is correct
49 Correct 65 ms 18204 KB Output is correct
50 Correct 50 ms 18452 KB Output is correct
51 Correct 52 ms 17212 KB Output is correct
52 Correct 30 ms 14536 KB Output is correct
53 Correct 21 ms 13516 KB Output is correct
54 Correct 31 ms 16316 KB Output is correct
55 Correct 52 ms 17952 KB Output is correct
56 Correct 37 ms 17976 KB Output is correct
57 Correct 35 ms 16836 KB Output is correct
58 Correct 36 ms 17180 KB Output is correct
59 Correct 50 ms 17968 KB Output is correct
60 Correct 51 ms 18020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11980 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 6 ms 11964 KB Output is correct
4 Correct 7 ms 11980 KB Output is correct
5 Correct 8 ms 12056 KB Output is correct
6 Correct 6 ms 11980 KB Output is correct
7 Correct 7 ms 12020 KB Output is correct
8 Correct 8 ms 11980 KB Output is correct
9 Correct 7 ms 11980 KB Output is correct
10 Correct 6 ms 11980 KB Output is correct
11 Correct 7 ms 11980 KB Output is correct
12 Correct 7 ms 11980 KB Output is correct
13 Correct 6 ms 12056 KB Output is correct
14 Correct 6 ms 11980 KB Output is correct
15 Correct 6 ms 11980 KB Output is correct
16 Correct 7 ms 11980 KB Output is correct
17 Correct 6 ms 12008 KB Output is correct
18 Correct 8 ms 12056 KB Output is correct
19 Correct 6 ms 11980 KB Output is correct
20 Correct 7 ms 12004 KB Output is correct
21 Correct 7 ms 11980 KB Output is correct
22 Correct 8 ms 12052 KB Output is correct
23 Correct 7 ms 11980 KB Output is correct
24 Correct 9 ms 12056 KB Output is correct
25 Correct 8 ms 11980 KB Output is correct
26 Correct 6 ms 12084 KB Output is correct
27 Correct 7 ms 12024 KB Output is correct
28 Correct 7 ms 12052 KB Output is correct
29 Correct 6 ms 11980 KB Output is correct
30 Correct 7 ms 12056 KB Output is correct
31 Correct 7 ms 12108 KB Output is correct
32 Correct 8 ms 12092 KB Output is correct
33 Correct 8 ms 12184 KB Output is correct
34 Correct 8 ms 12108 KB Output is correct
35 Correct 8 ms 12236 KB Output is correct
36 Correct 8 ms 12108 KB Output is correct
37 Correct 8 ms 12108 KB Output is correct
38 Correct 9 ms 12108 KB Output is correct
39 Correct 8 ms 12108 KB Output is correct
40 Correct 8 ms 12108 KB Output is correct
41 Correct 7 ms 12108 KB Output is correct
42 Correct 8 ms 12112 KB Output is correct
43 Correct 8 ms 12192 KB Output is correct
44 Correct 7 ms 12236 KB Output is correct
45 Correct 7 ms 12236 KB Output is correct
46 Correct 30 ms 15248 KB Output is correct
47 Correct 48 ms 16324 KB Output is correct
48 Correct 52 ms 16868 KB Output is correct
49 Correct 65 ms 18204 KB Output is correct
50 Correct 50 ms 18452 KB Output is correct
51 Correct 52 ms 17212 KB Output is correct
52 Correct 30 ms 14536 KB Output is correct
53 Correct 21 ms 13516 KB Output is correct
54 Correct 31 ms 16316 KB Output is correct
55 Correct 52 ms 17952 KB Output is correct
56 Correct 37 ms 17976 KB Output is correct
57 Correct 35 ms 16836 KB Output is correct
58 Correct 36 ms 17180 KB Output is correct
59 Correct 50 ms 17968 KB Output is correct
60 Correct 51 ms 18020 KB Output is correct
61 Correct 120 ms 27712 KB Output is correct
62 Correct 140 ms 29596 KB Output is correct
63 Correct 179 ms 33580 KB Output is correct
64 Correct 230 ms 39308 KB Output is correct
65 Correct 240 ms 44216 KB Output is correct
66 Correct 273 ms 38040 KB Output is correct
67 Correct 196 ms 32880 KB Output is correct
68 Correct 103 ms 22428 KB Output is correct
69 Correct 132 ms 33428 KB Output is correct
70 Correct 241 ms 42100 KB Output is correct
71 Correct 147 ms 41336 KB Output is correct
72 Correct 145 ms 36240 KB Output is correct
73 Correct 173 ms 40320 KB Output is correct
74 Correct 188 ms 42688 KB Output is correct
75 Correct 203 ms 42640 KB Output is correct