Submission #466110

#TimeUsernameProblemLanguageResultExecution timeMemory
466110pdstiagoGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define mxn 200005 #define mxm 105 #define f first #define s second #define pb push_back #define es " " #define endl '\n' #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3f #define ll long long #define fastio ios_base::sync_with_stdio(0), cin.tie(0) #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() typedef pair<string, string> pii; typedef pair<int, pii> pip; int n, v[mxn], ma, pos, can[mxn], cont, need[mxn]; ll resp; int main(){ fastio; cin >> n; for(int i=1; i<=n; i++){ cin >> v[i]; if(v[i]>=ma){ ma=v[i]; pos=i; } } for(int i=n; i>=pos; i--){ if(v[i]<=v[i+1]+need[i+1]){ need[i]=(v[i+1]+need[i+1])-v[i]+1; } } for(int i=1; i<=pos; i++){ if(v[i]<=v[i-1]+need[i-1]){ need[i]=(v[i-1]+need[i-1])-v[i]+1; } } int atual=INF, past; for(int i=1; i<=pos; i++){ if(v[i]<atual){ cont++; atual=0; } atual=max(atual, v[i]); can[i]=cont; } for(int i=pos+1; i<=n; i++){ if(v[i]>atual){ cont++; atual=0; } atual=min(atual, v[i]); can[i]=cont; } atual=0; for(int i=1; i<=n+1; i++){ if(can[i]!=can[i-1]){ resp+=atual; atual=0; } atual=max(atual, need[i]); } cout << resp; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:44:20: warning: unused variable 'past' [-Wunused-variable]
   44 |     int atual=INF, past;
      |                    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...