QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#876289#9961. CowsMatutinoWA 1ms3840kbC++171.0kb2025-01-30 19:42:232025-01-30 19:42:23

Judging History

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

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

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,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){
            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;
        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: 1ms
memory: 3840kb

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 1ms
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: -100
Wrong Answer
time: 0ms
memory: 3840kb

input:

8
6 0 5 5 6 3 0 6

output:

5

result:

wrong answer 1st numbers differ - expected: '4', found: '5'