제출 #1010461

#제출 시각아이디문제언어결과실행 시간메모리
1010461m5588ohammedGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms348 KiB
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin>>n; int arr[n],a[n]; for(int i=0;i<n;i++){ cin>>arr[i]; a[i]=arr[i]; } int pre[n+1]={},suf[n+1]={},ansP[n+1]={},ansS[n+1]={}; for(int i=1;i<n;i++){ if(pre[i]<=arr[i-1]-arr[i]){ pre[i]=((arr[i-1]-arr[i])-pre[i])+1; arr[i]=arr[i-1]+1; } else if(arr[i-1]-arr[i]>0) pre[i]=(arr[i-1]-arr[i])+1; } for(int i=n-2;i>=0;i--){ if(suf[i]<=a[i+1]-a[i]){ suf[i]=((a[i+1]-a[i])-suf[i])+1; a[i]=a[i+1]+1; } else if(a[i+1]-a[i]>0) suf[i]=(a[i+1]-a[i])+1; } int cnt=0; for(int i=1;i<n;i++){ if(pre[i]-pre[i-1]>0) cnt+=pre[i]-pre[i-1]; ansP[i]=cnt; } cnt=0; for(int i=n-2;i>=0;i--){ if(suf[i]-suf[i+1]>0) cnt+=suf[i]-suf[i+1]; ansS[i]=cnt; } int mn=1e18; for(int i=0;i<n;i++){ if(i==0) mn=min(mn,ansS[i]); else if(i==n-1) mn=min(mn,ansP[i]); else mn=min(mn,max(ansP[i],ansS[i+1])); } cout<<mn<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...