Submission #127040

# Submission time Handle Problem Language Result Execution time Memory
127040 2019-07-08T20:29:48 Z TadijaSebez Hacker (BOI15_hac) C++11
100 / 100
98 ms 22520 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1000050;
int a[N];
ll sum[N],p[N];
int main()
{
	int n;
	scanf("%i",&n);
	for(int i=1;i<=n;i++) scanf("%i",&a[i]),a[i+n]=a[i];
	for(int i=1;i<=n*2;i++) sum[i]=sum[i-1]+a[i];
	int sz=n+1>>1;
	for(int i=1;i<=n;i++) p[i]=sum[i+sz-1]-sum[i-1];
	for(int i=n+1;i<=n*2;i++) p[i]=p[i-n];
	deque<int> dq;
	for(int i=n-sz+2;i<=n;i++)
	{
		while(dq.size() && p[dq.back()]>=p[i]) dq.pop_back();
		dq.push_back(i);
	}
	ll ans=0;
	for(int i=n+1;i<=2*n;i++)
	{
		while(dq.size() && p[dq.back()]>=p[i]) dq.pop_back();
		dq.push_back(i);
		while(dq.front()<i-sz+1) dq.pop_front();
		ans=max(ans,p[dq.front()]);
	}
	printf("%lld\n",ans);
	return 0;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:13:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int sz=n+1>>1;
         ~^~
hac.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
hac.cpp:11:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%i",&a[i]),a[i+n]=a[i];
                        ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# 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 376 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 376 KB Output is correct
11 Correct 2 ms 376 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 380 KB Output is correct
18 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 376 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 376 KB Output is correct
11 Correct 2 ms 376 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 380 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 504 KB Output is correct
23 Correct 3 ms 636 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 632 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 3 ms 632 KB Output is correct
31 Correct 3 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 17 ms 3832 KB Output is correct
5 Correct 37 ms 8924 KB Output is correct
6 Correct 50 ms 11256 KB Output is correct
7 Correct 60 ms 13388 KB Output is correct
8 Correct 97 ms 22008 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 376 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 376 KB Output is correct
11 Correct 2 ms 376 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 380 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 504 KB Output is correct
23 Correct 3 ms 636 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 632 KB Output is correct
26 Correct 3 ms 632 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 3 ms 632 KB Output is correct
31 Correct 3 ms 636 KB Output is correct
32 Correct 2 ms 380 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 3 ms 632 KB Output is correct
35 Correct 17 ms 3832 KB Output is correct
36 Correct 37 ms 8924 KB Output is correct
37 Correct 50 ms 11256 KB Output is correct
38 Correct 60 ms 13388 KB Output is correct
39 Correct 97 ms 22008 KB Output is correct
40 Correct 5 ms 888 KB Output is correct
41 Correct 5 ms 1144 KB Output is correct
42 Correct 8 ms 1656 KB Output is correct
43 Correct 40 ms 9080 KB Output is correct
44 Correct 97 ms 22008 KB Output is correct
45 Correct 20 ms 4592 KB Output is correct
46 Correct 59 ms 13432 KB Output is correct
47 Correct 98 ms 22136 KB Output is correct
48 Correct 77 ms 22364 KB Output is correct
49 Correct 80 ms 22520 KB Output is correct
50 Correct 80 ms 22520 KB Output is correct