Submission #198443

# Submission time Handle Problem Language Result Execution time Memory
198443 2020-01-26T04:25:34 Z dndhk Hacker (BOI15_hac) C++14
100 / 100
140 ms 12636 KB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

const int MAX_N = 500000;

typedef pair<int, int> pii;

int N;
int arr[MAX_N+1], sum[MAX_N+1];
int c[MAX_N+1];

vector<pii> vt;

int main(){
	scanf("%d", &N);
	for(int i=1; i<=N; i++){
		scanf("%d", &arr[i]);
		sum[i] = sum[i-1] + arr[i];
	}
	for(int i=1; i<=N; i++){
		if(i+(N/2)-1<=N){
			c[i] = sum[i+(N/2)-1] - sum[i-1];
		}else{
			c[i] = sum[N] - sum[i-1] + sum[(i+(N/2)-1)%N];
		}
		vt.pb({c[i], i});
	}
	sort(vt.begin(), vt.end());
	int s = vt.back().second, e = (s+(N/2)-2)%N+1;
	vt.pop_back();
	while(!vt.empty()){
		int ns = vt.back().second, ne = (ns+(N/2)-2)%N+1;
		if(ns<=ne){
			if(s<=e){
				s = max(s, ns);
				e = min(e, ne);
				if(s>e)	break;
			}else{
				if(ne>=s){
					s = max(ns, s);
					e = ne;
					if(s>e)	break;
				}else{
					e = min(e, ne);
					s = ns;
					if(s>e)	break;
				}
			}
		}else{
			if(s<=e){
				if(ns<=e){
					s = max(ns, s);
					if(s>e)	break;
				}else{
					e = min(e, ne);
					if(s>e)	break;
				}
			}else{
				s = max(ns, s);
				e = min(ne, e);
			}
		}
		vt.pop_back();
	}
	printf("%d\n", sum[N] - vt.back().first);

}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
hac.cpp:20: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 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 380 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 380 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 508 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 8 ms 504 KB Output is correct
26 Correct 7 ms 504 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 6 ms 376 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 7 ms 504 KB Output is correct
4 Correct 25 ms 2800 KB Output is correct
5 Correct 55 ms 5356 KB Output is correct
6 Correct 69 ms 6500 KB Output is correct
7 Correct 83 ms 9392 KB Output is correct
8 Correct 135 ms 12508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 380 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 508 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 8 ms 504 KB Output is correct
26 Correct 7 ms 504 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 6 ms 376 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 7 ms 504 KB Output is correct
35 Correct 25 ms 2800 KB Output is correct
36 Correct 55 ms 5356 KB Output is correct
37 Correct 69 ms 6500 KB Output is correct
38 Correct 83 ms 9392 KB Output is correct
39 Correct 135 ms 12508 KB Output is correct
40 Correct 9 ms 1016 KB Output is correct
41 Correct 11 ms 1016 KB Output is correct
42 Correct 12 ms 1144 KB Output is correct
43 Correct 64 ms 5484 KB Output is correct
44 Correct 133 ms 12380 KB Output is correct
45 Correct 29 ms 2928 KB Output is correct
46 Correct 77 ms 9316 KB Output is correct
47 Correct 132 ms 12440 KB Output is correct
48 Correct 97 ms 12636 KB Output is correct
49 Correct 140 ms 11996 KB Output is correct
50 Correct 138 ms 11872 KB Output is correct