# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
756711 | dzdzx | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 2 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |