답안 #867771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867771 2023-10-29T12:48:33 Z dio_2 Hacker (BOI15_hac) C++17
40 / 100
1000 ms 30884 KB
#include<bits/stdc++.h>
using namespace std;

const int MAX_N = 12 * 500'000;

int ST[MAX_N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	for(int i = 1;i <= MAX_N;i++) ST[i] = -(int)1e9;
	
	int N;
	cin >> N;
	
	const int NN = 3 * N;
	
	vector<int> A(N);
	for(int &x : A) cin >> x; // A[i] <= 2000

	for(int i = 0;i < N;i++) A.push_back(A[i]);
	for(int i = 0;i < N;i++) A.push_back(A[i]);
	
	vector<array<int, 3>> wids;
	auto add = [&](int s, int l, int r)->void{
		wids.push_back({s, l, r});
	};
	
	int K = (N + 1) / 2;
	int sum = 0;
	for(int i = 0;i < K;i++){
		sum += A[N-K+i+1];
	}
	
	add(sum, N-K+1, N);
	
	for(int i = N + 1;i < 3 * N;++i){
		sum += A[i];
		sum -= A[i - K];
		add(sum, i - K + 1, i);
	}
	
	vector<int> in(NN, -1), out(NN, -1);
	vector<int> sums;
	int id = 0;
	for(auto [s, l, r] : wids){
		sums.push_back(s);
		swap(l, r);
		if(in[l] == -1) in[l] = id;
		if(out[r] == -1 && in[r] != -1) out[r] = id;
		++id;
	}
	
	int ans = 0;
	
	for(int i = 0;i < NN;i++){
		int res = 1000 * NN;
		if(in[i] == -1 || out[i] == -1) continue;
		for(int j = in[i];j <= out[i];j++) res = min(res, sums[j]);
		ans = max(ans, res);
	}
	
	cout << ans << '\n';
	
	return 0;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:12:38: warning: iteration 5999999 invokes undefined behavior [-Waggressive-loop-optimizations]
   12 |  for(int i = 1;i <= MAX_N;i++) ST[i] = -(int)1e9;
      |                                ~~~~~~^~~~~~~~~~~
hac.cpp:12:18: note: within this loop
   12 |  for(int i = 1;i <= MAX_N;i++) ST[i] = -(int)1e9;
      |                ~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 4 ms 23728 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23920 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 5 ms 23900 KB Output is correct
9 Correct 5 ms 23968 KB Output is correct
10 Correct 5 ms 23900 KB Output is correct
11 Correct 5 ms 23892 KB Output is correct
12 Correct 5 ms 23900 KB Output is correct
13 Correct 5 ms 23900 KB Output is correct
14 Correct 5 ms 23696 KB Output is correct
15 Correct 6 ms 23900 KB Output is correct
16 Correct 6 ms 23900 KB Output is correct
17 Correct 5 ms 23900 KB Output is correct
18 Correct 5 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 4 ms 23728 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23920 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 5 ms 23900 KB Output is correct
9 Correct 5 ms 23968 KB Output is correct
10 Correct 5 ms 23900 KB Output is correct
11 Correct 5 ms 23892 KB Output is correct
12 Correct 5 ms 23900 KB Output is correct
13 Correct 5 ms 23900 KB Output is correct
14 Correct 5 ms 23696 KB Output is correct
15 Correct 6 ms 23900 KB Output is correct
16 Correct 6 ms 23900 KB Output is correct
17 Correct 5 ms 23900 KB Output is correct
18 Correct 5 ms 23900 KB Output is correct
19 Correct 5 ms 23900 KB Output is correct
20 Correct 6 ms 23948 KB Output is correct
21 Correct 6 ms 23900 KB Output is correct
22 Correct 11 ms 24156 KB Output is correct
23 Correct 23 ms 24212 KB Output is correct
24 Correct 11 ms 24156 KB Output is correct
25 Correct 22 ms 24156 KB Output is correct
26 Correct 22 ms 24156 KB Output is correct
27 Correct 5 ms 23900 KB Output is correct
28 Correct 5 ms 23700 KB Output is correct
29 Correct 5 ms 23900 KB Output is correct
30 Correct 23 ms 24408 KB Output is correct
31 Correct 22 ms 24156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 24 ms 24156 KB Output is correct
4 Execution timed out 1008 ms 30884 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 4 ms 23728 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23920 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 5 ms 23900 KB Output is correct
9 Correct 5 ms 23968 KB Output is correct
10 Correct 5 ms 23900 KB Output is correct
11 Correct 5 ms 23892 KB Output is correct
12 Correct 5 ms 23900 KB Output is correct
13 Correct 5 ms 23900 KB Output is correct
14 Correct 5 ms 23696 KB Output is correct
15 Correct 6 ms 23900 KB Output is correct
16 Correct 6 ms 23900 KB Output is correct
17 Correct 5 ms 23900 KB Output is correct
18 Correct 5 ms 23900 KB Output is correct
19 Correct 5 ms 23900 KB Output is correct
20 Correct 6 ms 23948 KB Output is correct
21 Correct 6 ms 23900 KB Output is correct
22 Correct 11 ms 24156 KB Output is correct
23 Correct 23 ms 24212 KB Output is correct
24 Correct 11 ms 24156 KB Output is correct
25 Correct 22 ms 24156 KB Output is correct
26 Correct 22 ms 24156 KB Output is correct
27 Correct 5 ms 23900 KB Output is correct
28 Correct 5 ms 23700 KB Output is correct
29 Correct 5 ms 23900 KB Output is correct
30 Correct 23 ms 24408 KB Output is correct
31 Correct 22 ms 24156 KB Output is correct
32 Correct 5 ms 23900 KB Output is correct
33 Correct 5 ms 23900 KB Output is correct
34 Correct 24 ms 24156 KB Output is correct
35 Execution timed out 1008 ms 30884 KB Time limit exceeded
36 Halted 0 ms 0 KB -