Submission #756711

#TimeUsernameProblemLanguageResultExecution timeMemory
756711dzdzxGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
2 ms340 KiB
#include <bits/stdc++.h> #define int long long using namespace std; main(){ int n; cin>>n; int a[n+1]; for (int i=1;i<=n;i++)cin>>a[i]; int l=-1,r=3000000001; while (r-l>1){ int m=(r+l)/2; int pref[n+1],suff[n+1]; int b[n+1]; for (int i=1;i<=n;i++)b[i]=a[i]; pref[1]=1; suff[n]=1; bool check=false; for (int i=2;i<=n;i++){ if (pref[i-1]==0){ pref[i]=0; continue; } if (b[i-1]+1-b[i]>m){ pref[i]=0; continue; } pref[i]=1; if (b[i]>b[i-1])continue; b[i]=b[i-1]+1; } for (int i=1;i<=n;i++)b[i]=a[i]; for (int i=n-1;i>=1;i--){ if (suff[i+1]==0){ suff[i]=0; continue; } if (b[i+1]+1-b[i]>m){ suff[i]=0; continue; } suff[i]=1; if (b[i]>b[i+1])continue; b[i]=b[i+1]+1; } // for (int i=1;i<=n;i++)cout<<m<<" "<<pref[i]<<" "<<suff[i]<<"\n"; if (m<0)check=false; for (int i=1;i<=n;i++)if (pref[i]==1 && suff[i]==1)check=true; if (check){ r=m; }else l=m; } cout<<r; }

Compilation message (stderr)

Main.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...