QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#883085 | #9961. Cows | Daniel777 | WA | 1ms | 5848kb | C++14 | 1.6kb | 2025-02-05 14:40:07 | 2025-02-05 14:40:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int a[N],n;
int f[N][2];
bool check(int m,bool flag = 0)
{
int ty = 2;
int L1 = 1,R1 = 0,L2 = 1,R2 = 0;
for(int i = 1;i <= n;i++)
{
if(ty == 2)
{
if(R1-L1+1 + R2-L2+1 + m < a[i])
{
ty = 1;
L1 = m-(a[i] - m - (R1-L1+1 + R2-L2+1))+1,R1 = m;
}
else
{
int x1 = L1-1,x2 = R1+R1-L1+1,x3 = L2+R1-L1,x4 = R2+R2-L2+1+R1-L1+1;
if(a[i] >= x3) L1 = L2-1 + (a[i]-x3+1)/2+1;
else if(a[i] >= x2) L1 = R1 + a[i]-x2+1;
else if(a[i] >= x1) L1 = L1-1 + (a[i]-x1+1)/2+1;
else L1 = a[i]+1;
R1 = m;
L2 = m+1,R2 = m;
}
}
else
{
if(a[i] < L1)
{
ty = 2;
L2 = R1+1;
R2 = m;
R1 = L1-1;
L1 = a[i]+1;
}
else
{
R1 = L1 - 1;
L1 = R1 - (a[i] - R1)+1;
}
}
if(flag) cout<<ty<<" "<<L1<<" "<<R1<<" "<<L2<<" "<<R2<<"\n";
if(ty == 1 && L1 < 0) return 0;
}
return ty == 2;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
cin>>n;
for(int i = 1;i <= n;i++) cin>>a[i];
int L = 1,R = 1e9;
while(L < R)
{
int mid = (L+R>>1);
if(check(mid)) R = mid;
else L = mid+1;
}
cout<<L<<"\n";
//check(L,1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
input:
5 5 4 0 4 6
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
3 1 4 6
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
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: 5848kb
input:
6 7 6 5 2 6 8
output:
7
result:
ok 1 number(s): "7"
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3712kb
input:
10 5 9 3 4 3 2 5 8 2 3
output:
5
result:
wrong answer 1st numbers differ - expected: '6', found: '5'