제출 #854096

#제출 시각아이디문제언어결과실행 시간메모리
854096ancuber1031Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
0 ms348 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define p_q priority_queue #define endl '\n' #define pb push_back signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin>>n; vector<int> a(n+2); vector<int> dp1(n+2), dp2(n+2), lk1(n+2), lk2(n+2), h1(n+2), h2(n+2); for (int i = 1; i <= n; ++i) cin>>a[i]; dp1[1] = lk1[1] = dp2[n] = lk2[n] = 0; h1[1] = a[1]; h2[n] = a[n]; for (int i = 2; i <= n; ++i) { h1[i] = max(a[i],h1[i-1]+1); lk1[i] = max(h1[i]-a[i],0); dp1[i] = dp1[i-1]+lk1[i]-lk1[i-1]; //cout<<lk1[i]<<' '<<dp1[i]<<' '<<h1[i]<<endl; } for (int i = n-1; i > 0; --i) { h2[i] = max(a[i],h2[i+1]+1); lk2[i] = max(h2[i]-a[i],0); dp2[i] = dp2[i+1]+lk2[i]-lk2[i+1]; //cout<<lk2[i]<<' '<<dp2[i]<<' '<<h2[i]<<endl; } int ans = min(dp2[1],dp1[n]); for (int i = 2; i <= n; ++i) { int tmp = dp1[i-1]+dp2[i]-min(lk1[i-1],lk2[i]); if (h1[i-1] == h2[i] && lk1[i-1] == lk2[i]) tmp++; ans = min(ans,tmp); } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...