Submission #492688

# Submission time Handle Problem Language Result Execution time Memory
492688 2021-12-08T12:08:12 Z luka1234 Bigger segments (IZhO19_segments) C++14
100 / 100
249 ms 20780 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
ll n;
ll a[500001];
pair<ll,ll> dp[500001];
ll pref[500001];
int main(){
	cin>>n;
	for(int k=1;k<=n;k++){
		cin>>a[k];
		pref[k]=pref[k-1]+a[k];
		dp[k].ff=1e18;
	}
	dp[0].ss=1;
	for(int k=1;k<=n;k++){
		if(dp[k].ff>=dp[k-1].ff+a[k]){
			dp[k].ff=dp[k-1].ff+a[k];
			dp[k].ss=dp[k-1].ss;
		}
		int l=k+1,r=n,indic=0;
		while(l<r){
			int m=(l+r)/2;
			if(pref[m]-pref[k]>=dp[k].ff){
				r=m;
				indic=1;
			}
			else{
				l=m+1;
			}
		}
		if(pref[l]-pref[k]>=dp[k].ff)
		   indic=1;
		if(indic==1){
			dp[l].ff=pref[l]-pref[k];
			dp[l].ss=dp[k].ss+1;
		}
	}
	cout<<dp[n].ss;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 304 KB Output is correct
29 Correct 1 ms 300 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 304 KB Output is correct
29 Correct 1 ms 300 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 2 ms 320 KB Output is correct
33 Correct 2 ms 428 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 2 ms 336 KB Output is correct
37 Correct 2 ms 320 KB Output is correct
38 Correct 2 ms 316 KB Output is correct
39 Correct 2 ms 336 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 304 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 304 KB Output is correct
29 Correct 1 ms 300 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 2 ms 320 KB Output is correct
33 Correct 2 ms 428 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 2 ms 336 KB Output is correct
37 Correct 2 ms 320 KB Output is correct
38 Correct 2 ms 316 KB Output is correct
39 Correct 2 ms 336 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 304 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 316 KB Output is correct
46 Correct 27 ms 3784 KB Output is correct
47 Correct 37 ms 3780 KB Output is correct
48 Correct 39 ms 4148 KB Output is correct
49 Correct 42 ms 4356 KB Output is correct
50 Correct 41 ms 4316 KB Output is correct
51 Correct 44 ms 4372 KB Output is correct
52 Correct 23 ms 2256 KB Output is correct
53 Correct 15 ms 1488 KB Output is correct
54 Correct 21 ms 3592 KB Output is correct
55 Correct 43 ms 4296 KB Output is correct
56 Correct 25 ms 3900 KB Output is correct
57 Correct 26 ms 3784 KB Output is correct
58 Correct 31 ms 3784 KB Output is correct
59 Correct 32 ms 4004 KB Output is correct
60 Correct 30 ms 3944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 304 KB Output is correct
29 Correct 1 ms 300 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 2 ms 320 KB Output is correct
33 Correct 2 ms 428 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 2 ms 336 KB Output is correct
37 Correct 2 ms 320 KB Output is correct
38 Correct 2 ms 316 KB Output is correct
39 Correct 2 ms 336 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 304 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 316 KB Output is correct
46 Correct 27 ms 3784 KB Output is correct
47 Correct 37 ms 3780 KB Output is correct
48 Correct 39 ms 4148 KB Output is correct
49 Correct 42 ms 4356 KB Output is correct
50 Correct 41 ms 4316 KB Output is correct
51 Correct 44 ms 4372 KB Output is correct
52 Correct 23 ms 2256 KB Output is correct
53 Correct 15 ms 1488 KB Output is correct
54 Correct 21 ms 3592 KB Output is correct
55 Correct 43 ms 4296 KB Output is correct
56 Correct 25 ms 3900 KB Output is correct
57 Correct 26 ms 3784 KB Output is correct
58 Correct 31 ms 3784 KB Output is correct
59 Correct 32 ms 4004 KB Output is correct
60 Correct 30 ms 3944 KB Output is correct
61 Correct 123 ms 17800 KB Output is correct
62 Correct 168 ms 17892 KB Output is correct
63 Correct 158 ms 18392 KB Output is correct
64 Correct 193 ms 20416 KB Output is correct
65 Correct 221 ms 20752 KB Output is correct
66 Correct 249 ms 20712 KB Output is correct
67 Correct 163 ms 16788 KB Output is correct
68 Correct 81 ms 8392 KB Output is correct
69 Correct 127 ms 16956 KB Output is correct
70 Correct 201 ms 20780 KB Output is correct
71 Correct 112 ms 17864 KB Output is correct
72 Correct 135 ms 18248 KB Output is correct
73 Correct 145 ms 18764 KB Output is correct
74 Correct 195 ms 19164 KB Output is correct
75 Correct 153 ms 19144 KB Output is correct