Submission #167367

#TimeUsernameProblemLanguageResultExecution timeMemory
167367theboatmanBigger segments (IZhO19_segments)C++17
100 / 100
118 ms25792 KiB
#include <bits/stdc++.h> #define fi first #define se second #define y1 theboatman using namespace std; typedef long long ll; const int N = int(1e6) + 10; const int inf = int(1e9) + 10; const long long INF = ll(1e18) + 10; vector <ll> pref; ll get(int l, int r) { return pref[r] - (l ? pref[l - 1] : 0); } int main() { cin.tie(0); ios::sync_with_stdio(0); int n; cin >> n; vector <int> a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } pref.resize(n); for(int i = 0; i < n; i++) { pref[i] = (i ? pref[i - 1] + a[i] : a[i]); } vector <pair <ll, int> > dp(n); for(int i = 0; i < n; i++) { dp[i] = {get(0, i), 1}; } vector <pair <ll, int> > lazy(n, {INF, inf}); pair <ll, int> now = {0LL, -1}; for(int i = 0; i < n; i++) { now.fi += a[i]; now = min(now, lazy[i]); dp[i] = min(dp[i], now); if (i + 1 == n || get(i + 1, n - 1) < now.fi) { continue; } int l = i + 1, r = n - 1; while(l < r) { int c = l + r >> 1; if (get(i + 1, c) < now.fi) { l = c + 1; } else { r = c; } } lazy[l] = min(lazy[l], {get(i + 1, l), now.se - 1}); } cout << -dp[n - 1].se << "\n"; return 0; } /* */

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:57:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int c = l + r >> 1;
                     ~~^~~
#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...