QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#860785#9961. CowsNightmare07WA 1ms5964kbC++141.0kb2025-01-18 14:56:592025-01-18 15:01:18

Judging History

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

  • [2025-01-18 15:01:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5964kb
  • [2025-01-18 14:56:59]
  • 提交

answer

#include <bits/stdc++.h>

#define i64 long long

using namespace std;

const int N = 2e5 + 10;

int n;
int h[N], b[N], D[N], U[N];

bool Check(int x) {
	b[n + 1] = 0;
	for (int i = 1; i <= n; i ++) b[i] = x - h[i], D[i] = h[i], U[i] = x;
	for (int i = 1; i <= n; i ++) {
		
//		cout << x << ":\n";
//		for (int j = 1; j <= n; j ++) cout << b[j] << '-' << U[j] << "-" << D[j] << ' ';cout << endl;
		
		if (b[i] >= 0) {
			int k = min(b[i], (D[i + 1] - D[i]) / 2);
			if (k < 0) continue;
			b[i + 1] += k;
			b[i] -= k;
			D[i + 1] -= k;
		}
		else if (i != n) {
			int k = -b[i];
			b[i] += k;
			b[i + 1] -= k;
			U[i + 1] -= k;
			D[i] -= k;
			D[i] = max(D[i], k);
		}
	}
	bool st = true;
	for (int i = 1; i <= n; i ++)	
		if (b[i] < 0 || U[i] < D[i]) st = false;
	return st;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) scanf("%d", &h[i]);
	
	int l = 0, r = 1e9;
	while (l < r) {
		int mid = l + r >> 1;
		if (Check(mid)) r = mid;
		else l = mid + 1;
	}
	
	printf("%d", l);
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5964kb

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

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

input:

8
6 0 5 5 6 3 0 6

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

6
7 6 5 2 6 8

output:

6

result:

wrong answer 1st numbers differ - expected: '7', found: '6'