QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#843172#9961. Cowsucup-team987#WA 0ms3856kbC++201.9kb2025-01-04 17:06:372025-01-04 17:06:47

Judging History

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

  • [2025-01-04 17:06:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2025-01-04 17:06:37]
  • 提交

answer

#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
int N,H[2<<17];
bool check(int T)
{
	vector<pair<int,int> >X;
	bool lft=false;
	for(int i=0;i<N;i++)
	{
		if(X.empty())
		{
			if(H[i]>T)
			{
				int l=2*T-H[i];
				if(l<0)return false;
				X.push_back(make_pair(l,T));
				lft=true;
			}
			else
			{
				if(H[i]<T)X.push_back(make_pair(H[i],T));
				lft=false;
			}
		}
		else if(lft)
		{
			assert(X.size()==1);
			auto[l,r]=X[0];
			X.clear();
			if(l>=H[i])
			{
				if(H[i]<l)X.push_back(make_pair(H[i],l));
				if(r<T)X.push_back(make_pair(r,T));
				lft=false;
			}
			else
			{
				int nl=2*l-H[i];
				if(nl<0)return false;
				X.push_back(make_pair(nl,l));
				lft=true;
			}
		}
		else
		{
			int pos=0;
			int rest=H[i];
			if(rest==0)
			{
				X.clear();
				if(0<T)X.push_back(make_pair(0,T));
				lft=false;
			}
			else
			{
				for(int j=0;j<X.size();j++)
				{
					auto[l,r]=X[j];
					if(rest<=l-pos)
					{
						X.clear();
						if(pos+rest<T)X.push_back(make_pair(pos+rest,T));
						lft=false;
						rest=0;
						break;
					}
					rest-=l-pos;
					if(rest<=2*(r-l))
					{
						int u=l+(rest+1)/2;
						X.clear();
						if(u<T)X.push_back(make_pair(u,T));
						lft=false;
						rest=0;
						break;
					}
					rest-=2*(r-l);
					pos=r;
				}
				if(rest>0&&rest<=T-pos)
				{
					X.clear();
					if(pos+rest<T)X.push_back(make_pair(pos+rest,T));
					lft=false;
					rest=0;
				}
				if(rest>0)
				{
					int nl=T-rest;
					if(nl<0)return false;
					X.clear();
					X.push_back(make_pair(nl,T));
					lft=true;
				}
			}
		}
	}
	if(lft)return false;
	return true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	for(int i=0;i<N;i++)cin>>H[i];
	int L=-1,R=(int)1e9;
	while(R-L>1)
	{
		int M=(L+R)/2;
		if(check(M))R=M;
		else L=M;
	}
	cout<<R<<endl;
}

详细

Test #1:

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

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

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

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

input:

6
7 6 5 2 6 8

output:

7

result:

ok 1 number(s): "7"

Test #7:

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

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

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

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

input:

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

output:

107

result:

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