Submission #966084

#TimeUsernameProblemLanguageResultExecution timeMemory
966084oblantisGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
25 ms8792 KiB
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") //#pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define pb push_back #define ss second #define ff first #define vt vector #define uid(a, b) uniform_int_distribution<int>(a, b)(mt) using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int inf = 2e9; const int mod = 1e9+7; const int maxn = 1e6; mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); void solve() { int n; cin >> n; ll a[n], p[n], s[n], x[n], y[n]; for(int i = 0; i < n; i++){ cin >> a[i]; p[i] = s[i] = 0; } for(int i = 0; i < n; i++){ if(i)p[i] = p[i - 1] + max(0ll, a[i - 1] + 1 - a[i]); x[i] = a[i] + p[i]; } ll t = 0; for(int i = n - 1; i >= 0; i--){ t = max(t, a[i]); if((i + 1) < n)s[i] = s[i + 1] + max(0ll, a[i + 1] + 1 - a[i]); y[i] = t++; } ll ans = min(p[n - 1], s[0]); for(int i = 0; i < n - 1; i++){ ans = min(max(p[i], s[i + 1]) + (p[i] == s[i + 1] && a[i] == a[i + 1]), ans); } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int times = 1; //cin >> times; for(int i = 1; i <= times; i++) { solve(); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:21:26: warning: variable 'x' set but not used [-Wunused-but-set-variable]
   21 |     ll a[n], p[n], s[n], x[n], y[n];
      |                          ^
Main.cpp:21:32: warning: variable 'y' set but not used [-Wunused-but-set-variable]
   21 |     ll a[n], p[n], s[n], x[n], y[n];
      |                                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...