QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#876362#9961. CowsMatutinoWA 1ms3840kbC++171.7kb2025-01-30 20:12:142025-01-30 20:12:19

Judging History

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

  • [2025-01-30 20:12:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3840kb
  • [2025-01-30 20:12:14]
  • 提交

answer

#include<bits/stdc++.h>
#define reg register
#define int long long
inline int read(){
    reg int x=0,k=1; reg char ch=getchar();
    while (ch<'0'||ch>'9') (ch=='-')&&(k=-1),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*k;
}
const int N=3e5+10;
int n,a[N];
inline bool check(reg int lim){
    reg int l=1,r=0,L=1,R=0,lsty=lim,y=lim; // give get
    for (reg int i=1;i<=n;i++){
        // std::cerr<<l<<" "<<r<<" "<<y<<"\n";
        reg int t;
        if (y<=0) return 0;
        if (l<=r||L<=R){
            if (l<=r&&L<=R){
                if (a[i]<l) t=a[i];
                else if (a[i]<=r+r-l+1) t=l-1+((a[i]-(l-1)-1)/2+1);
                else{
                    reg int rest=a[i]-r-(r-l+1);
                    if (rest<=L-r-1) t=r+rest;
                    else if (rest>L-r-1+(R-L+1)*2) t=r+rest-(R-L+1);
                    else t=r+(rest-(L-r-1)-1)/2+1; 
                } 
            }else if (l<=r){
                if (a[i]<l) t=a[i];
                else if (a[i]>=r+r-l+1) t=a[i]-(r-l+1);
                else t=l-1+((a[i]-(l-1)-1)/2+1);
            }else if (L<=R){
                if (a[i]<L) t=a[i];
                else if (a[i]>=R+R-L+1) t=a[i]-(R-L+1);
                else t=L-1+((a[i]-(L-1)-1)/2+1);
            }
        }else t=a[i];
        l=t+1,r=y; L=lsty+1,R=lim,lsty=y;
        if (t>y) y=2*y-t; else y=lim;
    }
    return y==lim;
}
signed main(){
    n=read();
    for (reg int i=1;i<=n;i++) a[i]=read();
    reg int l=0,r=2e9,ans=-1;
    while (l<=r){
        reg int mid=l+r>>1;
        if (check(mid)) ans=mid,r=mid-1; else l=mid+1;
    }
    // check(4);
    printf("%lld\n",ans);
    return 0;
}  

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

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: 0ms
memory: 3840kb

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

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

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

input:

6
7 6 5 2 6 8

output:

6

result:

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