제출 #505171

#제출 시각아이디문제언어결과실행 시간메모리
505171DanerZeinGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
87 ms8652 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int n; cin>>n; vector<ll> x,y; ll ma=-1; for(int i=0;i<n;i++){ ll a; cin>>a; x.push_back(a); y.push_back(a); } vector<ll> in,de; in.push_back(0); de.resize(n+1); ll ac=0; for(int i=1;i<n;i++){ x[i]+=ac; if(x[i]<=x[i-1]){ ac+=(x[i-1]-x[i])+1; x[i]=x[i-1]+1; } in.push_back(ac); } ac=0; for(int i=n-2;i>=0;i--){ y[i]+=ac; if(y[i]<=y[i+1]){ ac+=(y[i+1]-y[i])+1; y[i]=y[i+1]+1; } de[i]=ac; //cout<<ac<<" "; } //cout<<endl; ll res=1e14+1; for(int i=0;i<n;i++){ ll rp=in[i]; rp+=max((ll)0,de[i]-in[i]); res=min(res,rp); } cout<<res<<endl; /*ll res=1e14+1; for(int k=0;k<min((int)vma.size(),2);k++){ int i=vma[k]; ll ac=0; vector<ll> y=x; ll c=0; for(int j=1;j<=i;j++){ if(y[j]<=y[j-1]){ ac+=(y[j-1]-y[j])+1; c+=(y[j-1]-y[j])+1; } } y[i]+=ac; for(int j=i+1;j<n;j++){ if(y[j-1]<=y[j]){ c+=(y[j]-y[j-1])+1; ac=0; y[j-1]=y[j]+1; } if(y[j]+ac>=y[j-1]){ ac=abs(y[j]-y[j-1])-1; } y[j]+=ac; } res=min(res,c); } cout<<res<<endl;*/ }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:7:6: warning: unused variable 'ma' [-Wunused-variable]
    7 |   ll ma=-1;
      |      ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...