QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#883689#9961. CowswdnmdwrnmmpWA 1ms5740kbC++141.7kb2025-02-05 18:03:052025-02-05 18:03:06

Judging History

This is the latest submission verdict.

  • [2025-02-05 18:03:06]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5740kb
  • [2025-02-05 18:03:05]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e5+5;
int n,a[N],b[N],c[N],t[N];
namespace bl{
    int ans;
    void dfs(int x) {
        if(x>=ans)return;
        if(*max_element(a+1,a+n+1)==0)return ans=x,void();
        vector<int>b(n+1);
        for(int i=0;i<1<<n;i++) {
            vector<int>ct(n+1);
            for(int j=1;j<=n;j++)b[j]=a[j];
            for(int j=0;j<n;j++) {
                if(!a[j+1]) {
                    if((i>>j&1)&&j!=n-1)ct[j+2]++;
                    else if(!(i>>j&1)&&j)ct[j]++;
                }else ct[j+1]++;
            }
            for(int j=1;j<=n;j++)a[j]=max(0,a[j]-ct[j]);
            dfs(x+1);
            for(int j=1;j<=n;j++)a[j]=b[j];
        }
    }
    void solve() {
        ans=2e9,dfs(0);
        cout<<ans<<'\n';
    }
}
bool chk(int x) {
    ll s=0;
    for(int i=1;i<=n;i++)b[i]=a[i],s+=x-b[i],t[i]=c[i]=0;
    if(s<0)return 0;
    ll now=0;
    for(int i=1;i<=n;i++) {
        if(b[i]>b[i-1]) {
            int v=min(t[i],(b[i]-b[i-1]+1)/2);
            b[i]=b[i-1]+v+max(0,b[i]-b[i-1]-2*v);
        }
        auto ck=[&](int y)->bool {
            if(i==1)return 1;
            if(b[i-1]<y)return b[i-1]<=c[i-1];
            int v=b[i-1]-y;
            return y+(v+1)/2<=c[i-1];
        };
        int l=0,r=x,mid,s=-1;
        while(l<=r)mid=l+r>>1,ck(mid)?l=mid+1,s=mid:r=mid-1;
        if(s==-1)return 0; c[i]=s;
        if(b[i]<c[i])t[i+1]+=c[i]-b[i];
    }return c[n]>=b[n];
}
int main() {
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    // bl::solve();
    int l=0,r=1e9,mid,ans;
    while(l<=r)mid=l+r>>1,chk(mid)?r=mid-1,ans=mid:l=mid+1;
    cout<<ans<<'\n';
    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: 0ms
memory: 3584kb

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 5680kb

input:

8
6 0 5 5 6 3 0 6

output:

5

result:

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