QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#842992#9961. Cowsucup-team3510#WA 1ms5740kbC++201.3kb2025-01-04 16:17:342025-01-04 16:17:34

Judging History

This is the latest submission verdict.

  • [2025-01-04 16:17:34]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5740kb
  • [2025-01-04 16:17:34]
  • Submitted

answer

#include<iostream>
#include<vector>
using namespace std;
int n,a[200010];
inline bool judge(int x)
{
	static vector<pair<int,int> > v[200010];
	static int h[200010],lim[200010];
	for(int i=1;i<=n;i++)
	{
		v[i].clear(),h[i]=0;
		if(h[i-1])
		{
			if(lim[i-1]>=a[i])
			{
				v[i].push_back({a[i]+1,lim[i-1]-a[i]});
				v[i].push_back({lim[i-1]+h[i-1],x-(lim[i-1]+h[i-1])+1});
			}
			else
			{
				h[i]=a[i]-lim[i-1];
				lim[i]=lim[i-1]-h[i];
				if(lim[i]<0)
				{
					return 0;
				}
			}
			continue;
		}
		int A=a[i];
		for(int j=0;j<v[i-1].size();j++)
		{
			int f=v[i-1][j].first;
			int g=v[i-1][j].second;
			if(!g)
			{
				continue;
			}
			int t=f+g-1;
			if(A<=f)
			{
				v[i].push_back({A+1,x-A});
				break;
			}
			if(g+t<=A)
			{
				A-=g;
			}
			else
			{
				int V=f+(A-(f-1)+1>>1)-1;
				v[i].push_back({V+1,x-V});
				break;
			}
		}
		if(v[i].empty())
		{
			if(A>x)
			{
				h[i]=A-x;
				lim[i]=x-h[i];
				if(lim[i]<0)
				{
					return 0;
				}
			}
			else
			{
				v[i].push_back({A+1,x-A});
			}
		}
	}
	return !h[n];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int l=0,r=1e9,ans;
	while(l<=r)
	{
		int mid=l+r>>1;
		judge(mid)?(r=(ans=mid)-1):(l=mid+1);
	}
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

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

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

input:

6
7 6 5 2 6 8

output:

6

result:

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