Submission #983939

#TimeUsernameProblemLanguageResultExecution timeMemory
983939vjudge1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
27 ms6276 KiB
//#pragma GCC optimize("Ofast,O3") //#pragma GCC target("avx,avx2") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debugger.cpp" #else #define debug(...) #endif template<class T> int len(T &a){ return a.size(); } using ll = long long; using pii = pair<int,int>; #define all(a) (a).begin(), (a).end() #define ff first #define ss second string fileio = ""; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int MOD = 1e9 + 7; const int inf = 1e9; const ll infl = 1e18; const int maxn = 1e5 + 1; void solve(){ int n; cin >> n; vector<int> a(n); for(auto &u : a){ cin >> u; } vector<ll> lef(n), rig(n); for(int i = 1; i < n; i ++){ lef[i] = lef[i - 1] + max(0, a[i - 1] - a[i] + 1); } for(int i = n - 2; i>= 0; i --){ rig[i] = rig[i + 1] + max(0, a[i + 1] - a[i] + 1); } ll ans = infl; for(int i = 0; i < n; i ++){ ans = min(ans, max(lef[i], rig[i])); } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); auto start = chrono::high_resolution_clock::now(); #ifndef LOCAL if(fileio.size()){ freopen((fileio + ".in").c_str(), "r", stdin); freopen((fileio + ".out").c_str(), "w", stdout); } #endif int testcases = 1; #ifdef Tests cin >> testcases; #endif while(testcases --){ solve(); if(testcases) cout << '\n'; #ifdef LOCAL else cout << '\n'; cout << "_________________________" << endl; #endif } #ifdef LOCAL auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start); cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl; #endif return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:58:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
   58 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
Main.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...