Submission #447801

#TimeUsernameProblemLanguageResultExecution timeMemory
447801Killer2501Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
129 ms17988 KiB
#include<bits/stdc++.h> #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define pii pair<ll, pll> using namespace std; using ll = long long; const int N = 2e5+55; const ll mod = 1e15+7; const ll mod1 = 1e9+1; const ll base = 311; const ll base1 = 331; ll m, n, t, k, a[N], tong, b[N], dp[N], c[N], lab[N], l[N], r[N], cnt, ans; string s[N]; vector<pll> adj[N]; vector<pll> e; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } bool check(ll x) { ll lf = n, rt = 1; l[1] = 0; for(int i = 2; i <= n; i ++) { l[i] = max(l[i-1], a[i-1] + l[i-1] + 1 - a[i]); if(l[i] > x) { lf = i - 1 ; break; } } r[n] = 0; for(int i = n-1; i > 0; i --) { r[i] = max(r[i+1], a[i+1] + r[i+1] + 1 - a[i]); if(r[i] > x) { rt = i + 1; break; } } return lf >= rt; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i ++) { cin >> a[i]; } ll lf = 0, rt = mod, mid; while(lf <= rt) { mid = (lf + rt) / 2; if(check(mid))rt = mid - 1; else lf = mid + 1; } cout << lf; } /* 1 5 9 1 2 3 2 1 3 2 -2 2 2 3 1 3 2 -3 2 2 3 1 1 4 7 1 4 5 8 2 5 2 2 5 1 1 5 6 1 1 2 2 1 2 4 3 2 1 4 1 1 5 6 1 2 3 -2 2 3 5 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...