Submission #854101

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
8541012023-09-26 06:45:16ancuber1031Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms504 KiB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int 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), mx1(n+2), mx2(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],0ll);
dp1[i] = dp1[i-1]+max(0ll,lk1[i]-mx1[i-1]);
mx1[i] = max(mx1[i-1],lk1[i]);
//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],0ll);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...