Submission #868509

#TimeUsernameProblemLanguageResultExecution timeMemory
868509mgl_diamondGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
22 ms6304 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; #define foru(i, l, r) for(int i=(l); i<=(r); ++i) #define ford(i, l, r) for(int i=(l); i>=(r); --i) #define fore(x, v) for(auto &x : v) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define fi first #define se second #define file "input" void setIO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(file".inp", "r")) { freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); } } const int N = 2e5+5; int n, a[N]; ll l[N], r[N]; int main() { setIO(); cin >> n; foru(i, 1, n) cin >> a[i]; foru(i, 1, n-1) { l[i] = l[i-1]; int diff = a[i+1] - a[i]; if (diff <= 0) l[i] += 1-diff; } ford(i, n-1, 1) { r[i] = r[i+1]; int diff = a[i+1] - a[i]; if (diff >= 0) r[i] += diff+1; } ll ans = 1e18; foru(i, 0, n-1) { // cout << l[i] << " " << r[i+1] << "\n"; ans = min(ans, max(l[i], r[i+1])); } cout << ans; }

Compilation message (stderr)

Main.cpp: In function 'void setIO()':
Main.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen(file".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen(file".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...