Submission #249424

# Submission time Handle Problem Language Result Execution time Memory
249424 2020-07-15T01:25:43 Z mahmoudbadawy Bigger segments (IZhO19_segments) C++17
100 / 100
424 ms 105080 KB
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;

const int N=5e5+5;

int arr[N];
set<pair<int,int> > cur[N];
long long sum[N];
int n;

int get(long long s,int i)
{
	int st=i,en=n,ans=n+1;
	while(st<=en)
	{
		int mid=(st+en)/2;
		if(sum[mid]-sum[i]>=s)
		{
			ans=mid;
			en=mid-1;
		}
		else
			st=mid+1;
	}
	return ans;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
		sum[i+1]=sum[i]+arr[i];
	}
	for(int i=1;i<n;i++)
	{
		int las=-1;
		cur[i].insert({1,1});
		while(cur[i].size())
		{
			auto x=*cur[i].rbegin();
			cur[i].erase(x);
			if(x.F==las)
				continue;
			cur[i+1].insert(x);
			int z=get(sum[i]-sum[x.S-1],i);
			cur[z].insert({x.F+1,i+1});
			if(las!=-1) break;
			las=x.F;
		}
	}
	if(!cur[n].size()) cur[n].insert({1,1});
	cout << (*cur[n].rbegin()).F << endl;
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
segments.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&arr[i]);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23832 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23832 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 14 ms 23820 KB Output is correct
18 Correct 15 ms 23936 KB Output is correct
19 Correct 14 ms 23936 KB Output is correct
20 Correct 14 ms 23936 KB Output is correct
21 Correct 14 ms 23808 KB Output is correct
22 Correct 14 ms 23808 KB Output is correct
23 Correct 15 ms 23808 KB Output is correct
24 Correct 15 ms 23808 KB Output is correct
25 Correct 15 ms 23936 KB Output is correct
26 Correct 14 ms 23936 KB Output is correct
27 Correct 14 ms 23936 KB Output is correct
28 Correct 14 ms 23808 KB Output is correct
29 Correct 14 ms 23936 KB Output is correct
30 Correct 14 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23832 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 14 ms 23820 KB Output is correct
18 Correct 15 ms 23936 KB Output is correct
19 Correct 14 ms 23936 KB Output is correct
20 Correct 14 ms 23936 KB Output is correct
21 Correct 14 ms 23808 KB Output is correct
22 Correct 14 ms 23808 KB Output is correct
23 Correct 15 ms 23808 KB Output is correct
24 Correct 15 ms 23808 KB Output is correct
25 Correct 15 ms 23936 KB Output is correct
26 Correct 14 ms 23936 KB Output is correct
27 Correct 14 ms 23936 KB Output is correct
28 Correct 14 ms 23808 KB Output is correct
29 Correct 14 ms 23936 KB Output is correct
30 Correct 14 ms 23936 KB Output is correct
31 Correct 14 ms 23936 KB Output is correct
32 Correct 16 ms 24192 KB Output is correct
33 Correct 16 ms 24320 KB Output is correct
34 Correct 16 ms 24320 KB Output is correct
35 Correct 21 ms 24320 KB Output is correct
36 Correct 16 ms 24192 KB Output is correct
37 Correct 16 ms 24064 KB Output is correct
38 Correct 16 ms 24064 KB Output is correct
39 Correct 16 ms 24192 KB Output is correct
40 Correct 16 ms 24192 KB Output is correct
41 Correct 16 ms 24320 KB Output is correct
42 Correct 16 ms 24320 KB Output is correct
43 Correct 16 ms 24192 KB Output is correct
44 Correct 15 ms 24320 KB Output is correct
45 Correct 22 ms 24192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23832 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 14 ms 23820 KB Output is correct
18 Correct 15 ms 23936 KB Output is correct
19 Correct 14 ms 23936 KB Output is correct
20 Correct 14 ms 23936 KB Output is correct
21 Correct 14 ms 23808 KB Output is correct
22 Correct 14 ms 23808 KB Output is correct
23 Correct 15 ms 23808 KB Output is correct
24 Correct 15 ms 23808 KB Output is correct
25 Correct 15 ms 23936 KB Output is correct
26 Correct 14 ms 23936 KB Output is correct
27 Correct 14 ms 23936 KB Output is correct
28 Correct 14 ms 23808 KB Output is correct
29 Correct 14 ms 23936 KB Output is correct
30 Correct 14 ms 23936 KB Output is correct
31 Correct 14 ms 23936 KB Output is correct
32 Correct 16 ms 24192 KB Output is correct
33 Correct 16 ms 24320 KB Output is correct
34 Correct 16 ms 24320 KB Output is correct
35 Correct 21 ms 24320 KB Output is correct
36 Correct 16 ms 24192 KB Output is correct
37 Correct 16 ms 24064 KB Output is correct
38 Correct 16 ms 24064 KB Output is correct
39 Correct 16 ms 24192 KB Output is correct
40 Correct 16 ms 24192 KB Output is correct
41 Correct 16 ms 24320 KB Output is correct
42 Correct 16 ms 24320 KB Output is correct
43 Correct 16 ms 24192 KB Output is correct
44 Correct 15 ms 24320 KB Output is correct
45 Correct 22 ms 24192 KB Output is correct
46 Correct 56 ms 29704 KB Output is correct
47 Correct 92 ms 34632 KB Output is correct
48 Correct 94 ms 39928 KB Output is correct
49 Correct 86 ms 40056 KB Output is correct
50 Correct 73 ms 40056 KB Output is correct
51 Correct 104 ms 35448 KB Output is correct
52 Correct 55 ms 29688 KB Output is correct
53 Correct 39 ms 27384 KB Output is correct
54 Correct 86 ms 34808 KB Output is correct
55 Correct 79 ms 35512 KB Output is correct
56 Correct 84 ms 39544 KB Output is correct
57 Correct 82 ms 39544 KB Output is correct
58 Correct 78 ms 38520 KB Output is correct
59 Correct 69 ms 39676 KB Output is correct
60 Correct 74 ms 36856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23832 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 14 ms 23820 KB Output is correct
18 Correct 15 ms 23936 KB Output is correct
19 Correct 14 ms 23936 KB Output is correct
20 Correct 14 ms 23936 KB Output is correct
21 Correct 14 ms 23808 KB Output is correct
22 Correct 14 ms 23808 KB Output is correct
23 Correct 15 ms 23808 KB Output is correct
24 Correct 15 ms 23808 KB Output is correct
25 Correct 15 ms 23936 KB Output is correct
26 Correct 14 ms 23936 KB Output is correct
27 Correct 14 ms 23936 KB Output is correct
28 Correct 14 ms 23808 KB Output is correct
29 Correct 14 ms 23936 KB Output is correct
30 Correct 14 ms 23936 KB Output is correct
31 Correct 14 ms 23936 KB Output is correct
32 Correct 16 ms 24192 KB Output is correct
33 Correct 16 ms 24320 KB Output is correct
34 Correct 16 ms 24320 KB Output is correct
35 Correct 21 ms 24320 KB Output is correct
36 Correct 16 ms 24192 KB Output is correct
37 Correct 16 ms 24064 KB Output is correct
38 Correct 16 ms 24064 KB Output is correct
39 Correct 16 ms 24192 KB Output is correct
40 Correct 16 ms 24192 KB Output is correct
41 Correct 16 ms 24320 KB Output is correct
42 Correct 16 ms 24320 KB Output is correct
43 Correct 16 ms 24192 KB Output is correct
44 Correct 15 ms 24320 KB Output is correct
45 Correct 22 ms 24192 KB Output is correct
46 Correct 56 ms 29704 KB Output is correct
47 Correct 92 ms 34632 KB Output is correct
48 Correct 94 ms 39928 KB Output is correct
49 Correct 86 ms 40056 KB Output is correct
50 Correct 73 ms 40056 KB Output is correct
51 Correct 104 ms 35448 KB Output is correct
52 Correct 55 ms 29688 KB Output is correct
53 Correct 39 ms 27384 KB Output is correct
54 Correct 86 ms 34808 KB Output is correct
55 Correct 79 ms 35512 KB Output is correct
56 Correct 84 ms 39544 KB Output is correct
57 Correct 82 ms 39544 KB Output is correct
58 Correct 78 ms 38520 KB Output is correct
59 Correct 69 ms 39676 KB Output is correct
60 Correct 74 ms 36856 KB Output is correct
61 Correct 237 ms 55160 KB Output is correct
62 Correct 292 ms 55164 KB Output is correct
63 Correct 424 ms 74832 KB Output is correct
64 Correct 394 ms 104696 KB Output is correct
65 Correct 312 ms 105080 KB Output is correct
66 Correct 418 ms 81784 KB Output is correct
67 Correct 333 ms 70392 KB Output is correct
68 Correct 175 ms 47096 KB Output is correct
69 Correct 388 ms 78200 KB Output is correct
70 Correct 348 ms 81912 KB Output is correct
71 Correct 292 ms 102136 KB Output is correct
72 Correct 362 ms 102520 KB Output is correct
73 Correct 328 ms 103100 KB Output is correct
74 Correct 300 ms 103672 KB Output is correct
75 Correct 307 ms 98424 KB Output is correct