Submission #870021

#TimeUsernameProblemLanguageResultExecution timeMemory
870021Megumin2006Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
26 ms12440 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int n; inline vector<int> get(vector<int> &a) { vector<int> r(n + 1), st, ans(n + 1); for(int i = n; i >= 1; --i) { while(st.size() && a[ st.back() ] > a[i]) st.pop_back(); r[i] = st.size() ? st.back() : -1; st.push_back(i); } for(int i = 1; i <= n; ++i) { ans[i] += ans[i - 1]; if (r[i] == -1) continue; ans[ r[i] ] += max(0ll, a[i] - a[ r[i] ] - ans[ r[i] ] + 1); } return ans; } void solve() { cin >> n; vector<int> a(n + 1); for(int i = 1; i <= n; ++i) { cin >> a[i]; } vector<int> ans1 = get(a); reverse(a.begin() + 1, a.end()); vector<int> ans2 = get(a); reverse(ans2.begin() + 1, ans2.end()); int ans = min(ans1[n], ans2[1]); for(int i = 1; i < n; ++i) { ans = min(ans, max(ans1[i], ans2[i])); } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("cf.inp", "r")) { freopen("cf.inp", "r", stdin); freopen("1.out", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen("cf.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen("1.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...