Submission #148285

# Submission time Handle Problem Language Result Execution time Memory
148285 2019-08-31T20:00:40 Z GioChkhaidze Bigger segments (IZhO19_segments) C++14
100 / 100
404 ms 20984 KB
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
long long n,a[500005],S[500005];
pair < long long , int > dp[500005];
main () {
	cin>>n;
	
	for (int i=1; i<=n; i++) {
		cin>>a[i];
		S[i]=S[i-1]+a[i];
		dp[i].F=1e18;
	}
	
	dp[0].S=1;
	
	for (int i=1; i<=n; i++) {
		if (dp[i].F>=dp[i-1].F+a[i]) dp[i].F=dp[i-1].F+a[i],dp[i].S=dp[i-1].S;
		int l=i+1,r=n,mid,idx=-1;
		
		while (l<=r) {
			mid=(l+r)/2;
			if (S[mid]-S[i]>=dp[i].F) { idx=mid; r=mid-1; }
				else l=mid+1;
		}
		
		if (idx==-1) continue;
		if (dp[idx].F>=S[idx]-S[i]) dp[idx].F=S[idx]-S[i],dp[idx].S=dp[i].S+1;
	}
	
	cout<<dp[n].S<<endl;
}

Compilation message

segments.cpp:7:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# 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 424 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 380 KB Output is correct
11 Correct 2 ms 404 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 424 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 380 KB Output is correct
11 Correct 2 ms 404 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 376 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 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 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 424 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 380 KB Output is correct
11 Correct 2 ms 404 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 376 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 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 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 4 ms 376 KB Output is correct
32 Correct 4 ms 476 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 504 KB Output is correct
35 Correct 4 ms 508 KB Output is correct
36 Correct 4 ms 504 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 3 ms 376 KB Output is correct
40 Correct 4 ms 504 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 3 ms 376 KB Output is correct
45 Correct 3 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 424 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 380 KB Output is correct
11 Correct 2 ms 404 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 376 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 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 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 4 ms 376 KB Output is correct
32 Correct 4 ms 476 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 504 KB Output is correct
35 Correct 4 ms 508 KB Output is correct
36 Correct 4 ms 504 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 3 ms 376 KB Output is correct
40 Correct 4 ms 504 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 3 ms 376 KB Output is correct
45 Correct 3 ms 376 KB Output is correct
46 Correct 43 ms 3872 KB Output is correct
47 Correct 54 ms 3992 KB Output is correct
48 Correct 72 ms 4372 KB Output is correct
49 Correct 78 ms 4344 KB Output is correct
50 Correct 80 ms 4600 KB Output is correct
51 Correct 89 ms 4584 KB Output is correct
52 Correct 42 ms 2388 KB Output is correct
53 Correct 26 ms 1528 KB Output is correct
54 Correct 35 ms 3704 KB Output is correct
55 Correct 81 ms 4436 KB Output is correct
56 Correct 49 ms 3960 KB Output is correct
57 Correct 47 ms 4076 KB Output is correct
58 Correct 48 ms 3960 KB Output is correct
59 Correct 57 ms 4092 KB Output is correct
60 Correct 58 ms 4216 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 424 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 380 KB Output is correct
11 Correct 2 ms 404 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 376 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 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 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 4 ms 376 KB Output is correct
32 Correct 4 ms 476 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 504 KB Output is correct
35 Correct 4 ms 508 KB Output is correct
36 Correct 4 ms 504 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 3 ms 376 KB Output is correct
40 Correct 4 ms 504 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 3 ms 376 KB Output is correct
45 Correct 3 ms 376 KB Output is correct
46 Correct 43 ms 3872 KB Output is correct
47 Correct 54 ms 3992 KB Output is correct
48 Correct 72 ms 4372 KB Output is correct
49 Correct 78 ms 4344 KB Output is correct
50 Correct 80 ms 4600 KB Output is correct
51 Correct 89 ms 4584 KB Output is correct
52 Correct 42 ms 2388 KB Output is correct
53 Correct 26 ms 1528 KB Output is correct
54 Correct 35 ms 3704 KB Output is correct
55 Correct 81 ms 4436 KB Output is correct
56 Correct 49 ms 3960 KB Output is correct
57 Correct 47 ms 4076 KB Output is correct
58 Correct 48 ms 3960 KB Output is correct
59 Correct 57 ms 4092 KB Output is correct
60 Correct 58 ms 4216 KB Output is correct
61 Correct 208 ms 17892 KB Output is correct
62 Correct 221 ms 18032 KB Output is correct
63 Correct 257 ms 18360 KB Output is correct
64 Correct 376 ms 20464 KB Output is correct
65 Correct 404 ms 20828 KB Output is correct
66 Correct 400 ms 20800 KB Output is correct
67 Correct 320 ms 16700 KB Output is correct
68 Correct 161 ms 8576 KB Output is correct
69 Correct 168 ms 17196 KB Output is correct
70 Correct 395 ms 20984 KB Output is correct
71 Correct 218 ms 17912 KB Output is correct
72 Correct 249 ms 18424 KB Output is correct
73 Correct 284 ms 18936 KB Output is correct
74 Correct 304 ms 19320 KB Output is correct
75 Correct 310 ms 19404 KB Output is correct