Submission #791796

# Submission time Handle Problem Language Result Execution time Memory
791796 2023-07-24T10:08:52 Z lovrot Hacker (BOI15_hac) C++17
100 / 100
54 ms 8140 KB
#include <cstdio> 
#include <queue>
#include <deque>

using namespace std; 

typedef long long ll;

const int N = 5e5 + 10;
const int oo = 2e9 + 10;

int n, V[N];

char B[N];
int S[N];

deque<int> Q;

void add(int x, deque<int> &A) {
	while(!A.empty() && A.back() > x) A.pop_back();
	A.push_back(x);
}

void pop(int x, deque<int> &A) {
	if(!A.empty() && A.front() == x) A.pop_front();
}

int get(deque<int> &A) {
	return A.empty() ? -1 : A.front(); 
}

int main() {
	scanf("%d", &n);
	int sum = 0, _sum = 0;
	for(int i = 0; i < n; ++i) { 
		scanf("%d", V + i); 
		sum += V[i]; 
		if(i < n / 2) _sum += V[i];
	}
	for(int i = n / 2 - 1; B[i] == 0;) {
		S[i] = sum - _sum;
		B[i] = 1;
		i = (i + 1) % n;
		_sum += V[i]; 
		_sum -= V[(i - n / 2 + n) % n];
	}
	for(int i = n / 2 - 1; i < n - 1; ++i)	add(S[i], Q);
	int ans = -oo;
	for(int i = n - 1; B[i] != 2;) {
		ans = max(ans, get(Q));
		B[i] = 2;
		pop(S[(i - (n + 1) / 2 + n) % n], Q);
		i = (i + 1) % n;
		add(S[(i - 1 + n) % n], Q); 
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
hac.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |   scanf("%d", V + i);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 9 ms 1368 KB Output is correct
5 Correct 21 ms 2776 KB Output is correct
6 Correct 28 ms 3576 KB Output is correct
7 Correct 32 ms 4204 KB Output is correct
8 Correct 54 ms 6756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 296 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 216 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 9 ms 1368 KB Output is correct
36 Correct 21 ms 2776 KB Output is correct
37 Correct 28 ms 3576 KB Output is correct
38 Correct 32 ms 4204 KB Output is correct
39 Correct 54 ms 6756 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 440 KB Output is correct
42 Correct 4 ms 600 KB Output is correct
43 Correct 22 ms 2924 KB Output is correct
44 Correct 54 ms 6872 KB Output is correct
45 Correct 11 ms 1464 KB Output is correct
46 Correct 32 ms 4196 KB Output is correct
47 Correct 54 ms 6832 KB Output is correct
48 Correct 46 ms 8140 KB Output is correct
49 Correct 45 ms 7156 KB Output is correct
50 Correct 46 ms 7180 KB Output is correct