Submission #2770749


Source Code Expand

Copy
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const long long inf = 1LL << 62;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector<long long> s(n + 1);
	s[0] = 0;
	for (int i = 0; i < n; ++i) {
		s[i + 1] = s[i] + a[i];
	}
	long long ret = inf;
	for (int i = 2; i <= n - 2; ++i) {
		int lh = lower_bound(s.begin(), s.begin() + i, (s[i] + 1) / 2) - s.begin();
		int rh = lower_bound(s.begin() + i, s.end(), (s[i] + s[n] + 1) / 2) - s.begin();
		long long lt = inf, rt = -inf;
		if (s[lh] * 2 - s[i] < s[i] - s[lh - 1] * 2) {
			lt = min(lt, s[i] - s[lh]);
			rt = max(rt, s[lh]);
		}
		else {
			lt = min(lt, s[lh - 1]);
			rt = max(rt, s[i] - s[lh - 1]);
		}
		if (s[rh] * 2 - s[i] - s[n] < s[i] + s[n] - s[rh - 1] * 2) {
			lt = min(lt, s[n] - s[rh]);
			rt = max(rt, s[rh] - s[i]);
		}
		else {
			lt = min(lt, s[rh - 1] - s[i]);
			rt = max(rt, s[n] - s[rh - 1]);
		}
		ret = min(ret, rt - lt);
	}
	cout << ret << '\n';
	return 0;
}

Submission Info

Submission Time
Task D - Equal Cut
User square1001
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1117 Byte
Status AC
Exec Time 35 ms
Memory 2688 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 43
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt, subtask_1_30.txt, subtask_1_31.txt, subtask_1_32.txt, subtask_1_33.txt, subtask_1_34.txt, subtask_1_35.txt, subtask_1_36.txt, subtask_1_37.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_01.txt AC 1 ms 256 KB
subtask_1_02.txt AC 34 ms 2432 KB
subtask_1_03.txt AC 17 ms 1280 KB
subtask_1_04.txt AC 24 ms 1664 KB
subtask_1_05.txt AC 1 ms 256 KB
subtask_1_06.txt AC 4 ms 512 KB
subtask_1_07.txt AC 19 ms 1664 KB
subtask_1_08.txt AC 10 ms 1152 KB
subtask_1_09.txt AC 18 ms 1536 KB
subtask_1_10.txt AC 21 ms 2048 KB
subtask_1_11.txt AC 30 ms 2304 KB
subtask_1_12.txt AC 12 ms 1280 KB
subtask_1_13.txt AC 21 ms 1664 KB
subtask_1_14.txt AC 6 ms 768 KB
subtask_1_15.txt AC 5 ms 512 KB
subtask_1_16.txt AC 13 ms 1536 KB
subtask_1_17.txt AC 13 ms 1280 KB
subtask_1_18.txt AC 2 ms 384 KB
subtask_1_19.txt AC 29 ms 2432 KB
subtask_1_20.txt AC 35 ms 2432 KB
subtask_1_21.txt AC 18 ms 1408 KB
subtask_1_22.txt AC 12 ms 1024 KB
subtask_1_23.txt AC 31 ms 2176 KB
subtask_1_24.txt AC 28 ms 2560 KB
subtask_1_25.txt AC 29 ms 2560 KB
subtask_1_26.txt AC 29 ms 2560 KB
subtask_1_27.txt AC 27 ms 2560 KB
subtask_1_28.txt AC 29 ms 2688 KB
subtask_1_29.txt AC 31 ms 2560 KB
subtask_1_30.txt AC 35 ms 2560 KB
subtask_1_31.txt AC 33 ms 2560 KB
subtask_1_32.txt AC 34 ms 2560 KB
subtask_1_33.txt AC 34 ms 2560 KB
subtask_1_34.txt AC 25 ms 2560 KB
subtask_1_35.txt AC 31 ms 2560 KB
subtask_1_36.txt AC 24 ms 2560 KB
subtask_1_37.txt AC 31 ms 2560 KB