Submission #497427

#TimeUsernameProblemLanguageResultExecution timeMemory
497427IerusBigger segments (IZhO19_segments)C++17
0 / 100
1 ms204 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize ("unroll-loops,Ofast,O3") #pragma GCC target("avx,avx2,fma") #define F first #define S second #define int long long #define sz(x) (int)x.size() #define pb push_back #define eb emplace_back #define all(x) (x).begin(),(x).end() //const int E = 5e5+777; //const long long inf = 1e18+777; //const int N = 3e3+777; //const int MOD = 1e9+7; int getfast(vector<int> v){ int n = sz(v); int pref[n+2]{}, a[n+2]{}; for(int i = 0; i < n; ++i) a[i+1] = v[i]; for(int i = 1; i <= n; ++i) pref[i] = pref[i-1] + a[i]; auto get = [&](int l, int r){ if(l == -1 || r == -1) return -(int)1e9; return pref[r] - pref[l-1]; }; auto check = [&](int pos){ int ans = 1, last = get(1, pos); for(int i = pos + 1; i <= n; ++i){ int L = i, R = n, res = -1; while(L <= R){ int M = (L + R) >> 1LL; if(last <= get(i, M)){ R = (res = M) - 1; }else L = M + 1; } if(last <= get(i, res)){ ++ans; }else break; int k = i; for(; k < res; ++k){ if(last + a[k] <= get(k+1, res)){ last += a[k]; }else break; } last = get(k, res); i = res; } return ans; }; int ans = 0; for(int i = 1; i <= n; ++i){ // cerr << i << ": " << check(i) << '\n'; ans = max(ans, check(i)); } return ans; } signed main(){ ios_base::sync_with_stdio(0), cin.tie(0),cout.tie(0); int n; cin >> n; vector<int> a(n); for(auto &i : a) cin >> i; cout << getfast(a); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...