Submission #902763

#TimeUsernameProblemLanguageResultExecution timeMemory
902763May27_thGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
28 ms7528 KiB
#include <bits/stdc++.h> #define int64_t long long #define double long double using namespace std; using type = int64_t; const long long mod = 1000000007, inf = 1e18; const int base = 33; const int N = 3e5 + 10; const int LG = 20; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int n; int64_t a[N], lf[N], rg[N]; void Solve() { cin >> n; for(int i = 1; i <= n; i ++) cin >> a[i]; for(int i = 1; i <= n; i ++){ lf[i] = lf[i - 1] + max(0LL, a[i - 1] + 1 - a[i]); } for(int i = n; i >= 1; i --){ rg[i] = rg[i + 1] + max(0LL, a[i + 1] + 1 - a[i]); } /*for(int i = 1; i <= n; i ++) cout << lf[i] << " "; cout << "\n"; for(int i = 1; i <= n; i ++) cout << rg[i] << " "; cout << "\n";*/ int64_t ans = inf; for(int i = 1; i <= n; i ++){ ans = min(ans, max(lf[i], rg[i])); } cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if(fopen("guard.in", "r")){ freopen("guard.in", "r", stdin); freopen("guard.out", "w", stdout); } if(fopen("A.inp", "r")){ freopen("A.inp", "r", stdin); freopen("A.out", "w", stdout); } int tc = 1; //cin >> tc; while(tc --){ Solve(); } }

Compilation message (stderr)

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