QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#861130#9961. CowsNightmare07WA 1ms5972kbC++141.2kb2025-01-18 16:17:042025-01-18 16:18:44

Judging History

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

  • [2025-01-18 16:18:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5972kb
  • [2025-01-18 16:17:04]
  • 提交

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];
int Tg[N];

bool Check(int x) {
	bool st = true;
	b[n + 1] = 0;
	for (int i = 1; i <= n; i ++) b[i] = x - h[i], D[i] = h[i], U[i] = x, Tg[i] = -1;
	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], min((D[i + 1] - D[i]) / 2, U[i] - D[i] + 1));
			if (k >= 0) {
				b[i + 1] += k;
				b[i] -= k;
				D[i + 1] -= k;
				D[i + 1] = max(D[i + 1], D[i] + k);
				U[i] -= k;	
			}
		}
		else if (i != n) {
			int k = -b[i];
			b[i] += k;
			b[i + 1] -= k;
			U[i + 1] -= k;
			D[i] -= k;
			Tg[i + 1] = k;
		}
		if (Tg[i] != -1) D[i - 1] = max(D[i] + Tg[i], D[i - 1]);
	}
	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: 5796kb

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

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

input:

8
6 0 5 5 6 3 0 6

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

6
7 6 5 2 6 8

output:

7

result:

ok 1 number(s): "7"

Test #7:

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

input:

10
5 9 3 4 3 2 5 8 2 3

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

input:

10
1 18 3 15 0 14 20 15 14 12

output:

14

result:

ok 1 number(s): "14"

Test #9:

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

input:

10
1 18 3 15 0 14 20 15 15 12

output:

15

result:

ok 1 number(s): "15"

Test #10:

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

input:

20
97 171 3 157 117 35 0 0 173 154 59 58 18 189 27 181 78 20 253 22

output:

101

result:

wrong answer 1st numbers differ - expected: '100', found: '101'