Submission #106881

# Submission time Handle Problem Language Result Execution time Memory
106881 2019-04-20T19:59:31 Z Pajaraja Hacker (BOI15_hac) C++17
100 / 100
106 ms 12664 KB
#include <bits/stdc++.h>
#define MAXN 500007
using namespace std; 
int a[MAXN],sm[MAXN],pr[MAXN],n,p,lg[MAXN],ng[MAXN];
int sum(int r)
{
	if(r>=p) return pr[r]-pr[r-p];
	else return pr[r]+(pr[n]-pr[n-p+r]);
}
int dist(int l,int r)
{
	if(r>l) return r-l;
	else return n-l+r;
}
int main()
{
	scanf("%d",&n); p=(n+1)/2;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) pr[i]=pr[i-1]+a[i];
	for(int i=1;i<=n;i++) sm[i]=sum(i);
	stack<int> st; sm[0]=0; st.push(0);
	for(int i=1;i<=n;i++)
	{
		while(sm[st.top()]>=sm[i]) st.pop();
		st.push(i);
	}
	for(int i=1;i<=n;i++)
	{
		while(sm[st.top()]>=sm[i]) st.pop();
		lg[i]=st.top();
		st.push(i);
	}
	while(!st.empty()) st.pop();
	sm[n+1]=0; st.push(n+1);
	for(int i=n;i>0;i--)
	{
		while(sm[st.top()]>=sm[i]) st.pop();
		st.push(i);
	}
	for(int i=n;i>0;i--)
	{
		while(sm[st.top()]>=sm[i]) st.pop();
		ng[i]=st.top();
		st.push(i);
	}
	int res=0;
	for(int i=1;i<=n;i++) if(dist(lg[i],i)+dist(i,ng[i])>=p+1) res=max(res,sm[i]);
	printf("%d",res);
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n); p=(n+1)/2;
  ~~~~~^~~~~~~~~
hac.cpp:18:29: 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("%d",&a[i]);
                        ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 18 ms 2304 KB Output is correct
5 Correct 40 ms 4984 KB Output is correct
6 Correct 53 ms 6332 KB Output is correct
7 Correct 71 ms 7556 KB Output is correct
8 Correct 98 ms 12280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 4 ms 512 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 18 ms 2304 KB Output is correct
36 Correct 40 ms 4984 KB Output is correct
37 Correct 53 ms 6332 KB Output is correct
38 Correct 71 ms 7556 KB Output is correct
39 Correct 98 ms 12280 KB Output is correct
40 Correct 4 ms 640 KB Output is correct
41 Correct 7 ms 768 KB Output is correct
42 Correct 11 ms 1020 KB Output is correct
43 Correct 45 ms 5112 KB Output is correct
44 Correct 106 ms 12260 KB Output is correct
45 Correct 29 ms 2680 KB Output is correct
46 Correct 62 ms 7544 KB Output is correct
47 Correct 100 ms 12280 KB Output is correct
48 Correct 66 ms 12536 KB Output is correct
49 Correct 72 ms 12664 KB Output is correct
50 Correct 73 ms 12664 KB Output is correct