이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/******************************************************************************
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=1e9;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |