QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#251376#5080. Folding StickSamNguyen05#WA 0ms3700kbC++201.4kb2023-11-14 17:06:302023-11-14 17:06:30

Judging History

你现在查看的是最新测评结果

  • [2023-11-14 17:06:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3700kb
  • [2023-11-14 17:06:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

template <class T1, class T2>
inline bool minimise(T1 &x, T2 y) {
	if (x > y) { x = y; return true; }
	return false;
}

template <class F>
inline int FIND_SMALLEST(int l, int r, F f) {
	int res = r + 1;
	while (l <= r) {
		int m = (l + r) >> 1;
		if (f(m)) res = m, r = m - 1;
		else l = m + 1;
	}
	return res;
}

template <class F>
inline int FIND_LARGEST(int l, int r, F f) {
	int res = l - 1;
	while (l <= r) {
		int m = (l + r) >> 1;
		if (f(m)) res = m, l = m + 1;
		else r = m - 1;
	}
	return res;
}

const int MAX = 1e5 + 7;
int N, pre[MAX];

void input() {
	cin >> N;
	pre[0] = 0;
	for (int i = 1; i <= N; i++) {
		cin >> pre[i];
		pre[i] += pre[i - 1];
	}
}

// x1 - x0 <= x2 - x1 <= x3 - x2 <= x4 - x3 <= ...

void solve() {
	int ans = pre[N];
	for (int i = N; i >= 1; i--) {
		int j = FIND_LARGEST(0, i, [&](int j) {
			int sum = pre[i] - pre[j];
			while (j > 0) {
				int k = FIND_SMALLEST(0, j - 1, [&](int k) {
					return pre[j] - pre[k] <= sum;
				});

				if (k >= j)
					return false;

				sum = pre[j] - pre[k];
				j = k;
			}
			return j == 0;
		});

		minimise(ans, max(pre[i] - pre[j], pre[N] - pre[i]));
	}

	cout << ans;
}
	
int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	input();
	solve();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

4
3 2 2 3

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

5
1 1 1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

7
1 3 2 3 4 2 2

output:

6

result:

ok single line: '6'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

9
5 6 3 4 8 8 2 2 5

output:

9

result:

ok single line: '9'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

10
5 6 3 4 8 6 2 1 8 5

output:

9

result:

ok single line: '9'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

10
5 8 1 2 6 8 4 3 6 5

output:

14

result:

ok single line: '14'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

3
4 2 1

output:

4

result:

ok single line: '4'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

14
7 2 2 2 2 3 4 1 3 5 4 3 1 6

output:

8

result:

ok single line: '8'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

35
46 93 64 27 72 55 77 11 17 17 79 83 74 26 32 101 54 112 92 111 77 60 51 19 105 11 68 7 100 49 88 54 106 80 57

output:

366

result:

ok single line: '366'

Test #10:

score: -100
Wrong Answer
time: 0ms
memory: 3616kb

input:

150
87 121 113 120 23 32 107 92 107 40 61 29 100 120 30 62 61 53 103 40 110 56 16 38 12 55 11 71 109 26 60 72 19 121 74 97 11 87 117 32 58 40 104 91 101 118 19 59 79 21 40 111 100 36 105 58 122 61 33 75 66 11 65 97 84 28 90 18 76 68 70 58 112 100 95 28 61 25 24 110 93 117 80 119 105 52 66 66 101 77 ...

output:

792

result:

wrong answer 1st lines differ - expected: '765', found: '792'