QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#849896#9961. Cowsas_lyrWA 1ms3968kbC++141017b2025-01-09 19:03:202025-01-09 19:03:21

Judging History

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

  • [2025-01-09 19:03:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3968kb
  • [2025-01-09 19:03:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=210000,INF=1e9;
int n;
int a[N];
bool check(int x){
	bool op=1;
	int t=0,tm=0;
	int la=1,ra=0,lb=1,rb=0;
	for(int i=1;i<=n;i++){
		if(op==0){
			int ht=t,htm=tm;
			if(a[i]+tm<=t){
				op=1;
				t=0,tm=0;
				la=a[i]+1,ra=ht-htm,lb=ht+1,rb=x;
			}
			else{
				t=ht-htm,tm=a[i]+htm-ht;
				if(tm>t)
					return 0;
			}
		}
		else{
			int res=a[i];
			if(la<=res){
				if(2*ra+2*(ra-la+1)<=res)
					res-=2*(ra-la+1);
				else
					res=la+(res-la)/2;
			}
			if(lb<=res){
				if(2*rb+2*(rb-lb+1)<=res)
					res-=2*(rb-lb+1);
				else
					res=lb+(res-lb)/2;
			}
			if(res<=x)
				la=1,ra=0,lb=res+1,rb=x;
			else{
				op=0;
				t=x,tm=res-x;
				la=1,ra=0,lb=1,rb=0;
			}
		}
	}
	return tm==0;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int l=0,r=INF;
	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: 1ms
memory: 3900kb

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

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

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: 1ms
memory: 3868kb

input:

6
7 6 5 2 6 8

output:

6

result:

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