QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#848539#9961. CowsFesdrerWA 0ms3732kbC++17746b2025-01-08 21:42:272025-01-08 21:42:27

Judging History

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

  • [2025-01-08 21:42:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3732kb
  • [2025-01-08 21:42:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,h[N];
inline bool check(int mid){
	int lt=mid,le=0,o=1;
	for(int i=1;i<=n;i++){
		if(o){
			int now=h[i],nt=-1,ne=-1;
			if(now<=lt)	lt=now,le=0,o=1;
			else{
				now-=lt;
				if(now<=2*(mid-lt))	lt+=(now+1)/2,le=0,o=1;
				else	le=now-2*(mid-lt),lt=mid,o=0;
			}
		}
		else{
			if(lt-le<1)	return 0;
			if(h[i]<=lt-le)	lt=h[i]+le,le=0,o=0;
			else	lt=lt-le,le=h[i]-lt,o=1;
		}
	}
	if(!o)	return 0;
	return 1;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>h[i];
	int l=1,r=1e9;
	while(l<r){
		int mid=(l+r)/2;
		if(check(mid))	r=mid;
		else	l=mid+1;
	}
	cout<<l<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

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

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: 3732kb

input:

6
7 6 5 2 6 8

output:

6

result:

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