Submission #535099

#TimeUsernameProblemLanguageResultExecution timeMemory
535099AktanGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> #define cerr cout #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template<class T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>; #define int long long #define ft first #define sc second const int mod=1e9+7,INF=1e17,N=2e5+5; int pr[N],sf[N],c[N],d[N]; main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin >> n; vector<int> a(n+2); for(int i=1;i<=n;i++){ cin >> a[i]; if(i==1){ pr[i]=0; } else{ pr[i]=pr[i-1]+max(((a[i]-a[i-1]-1)*-1),0ll); } } for(int i=n;i>=1;i--){ if(i==n){ sf[i]=0; } else{ sf[i]=sf[i+1]+max(((a[i]-a[i+1]-1)*-1),0ll); } } int ans=INF; a[0]=INF; a[n+1]=INF; for(int i=1;i<=n+1;i++){ if(a[i-1]==a[i]){ ans=min(ans,pr[i-1]+sf[i]+1); } else{ ans=min(ans,pr[i-1]+sf[i]); } } cout << ans; }

Compilation message (stderr)

Main.cpp:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   15 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...