QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#857021#9961. Cowsucup-team191#WA 1ms3712kbC++232.0kb2025-01-14 23:49:132025-01-14 23:49:14

Judging History

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

  • [2025-01-14 23:49:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3712kb
  • [2025-01-14 23:49:13]
  • 提交

answer

#include <bits/stdc++.h>
#define x first
#define X first
#define y second
#define Y second
#define pb push_back
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const int N = 2e5 + 2;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const char en='\n';
const ll LLINF=1ll<<60;

int n, h[N];

bool possible(int L) {
	bool state = 0;
	vector<pii> v = {};
	
	for (int i = 0; i < n; ++i) {
		if (state) {
			// trebam
			int l = v[0].first, r = v[0].second;
			v.clear();
			if (h[i] < l) {
				state = 0;
				if (h[i] + 1 < l) v.push_back({h[i] + 1, l - 1});
				if (r < L) v.push_back({r + 1, L});
			} else {
				int d = h[i] - l + 1;
				if (l - d <= 0) return 0;
				v.push_back({l - d, l - 1});
			}
		} else {
			// dajem
			int tot = 0;
			for (pii p : v) {
				tot += p.second - p.first + 1;
			}
			if (h[i] > L + tot) {
				int d = h[i] - L - tot;
				state = 1;
				if (L - d + 1 <= 0) return 0;
				v = {{L - d + 1, L}};
			} else {
				int lo = 0, hi = L;
				
				while (lo < hi) {
					int mid = (lo + hi) >> 1;
					int cnt = mid;
					
					for (pii p : v) {
						if (p.second <= mid) cnt += p.second - p.first + 1;
						else if (p.first <= mid) cnt += mid - p.first + 1;
					}
					
					if (cnt >= h[i]) hi = mid;
					else lo = mid + 1;
				}
				
				if (lo < L) v = {{lo + 1, L}};
			}
		}
		/*
		cout << i << ": " << state << " ";
		for (pii p : v) {
			cout << "(" << p.first << " " << p.second << ") ";
		} cout << "\n"; */
	}
	
	return (!state || v.empty());
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> h[i];
	
	
	//cout << possible(7) << "\n";
	
	int lo = 0, hi = 1e9;
	
	while (lo < hi) {
		int mid = (lo + hi) >> 1;
		if (possible(mid)) hi = mid;
		else lo = mid + 1;
	}
	
	cout << lo << "\n";
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

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

input:

8
6 0 5 5 6 3 0 6

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

6
7 6 5 2 6 8

output:

7

result:

ok 1 number(s): "7"

Test #7:

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

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: 0ms
memory: 3584kb

input:

10
1 18 3 15 0 14 20 15 14 12

output:

14

result:

ok 1 number(s): "14"

Test #9:

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

input:

10
1 18 3 15 0 14 20 15 15 12

output:

14

result:

wrong answer 1st numbers differ - expected: '15', found: '14'