제출 #176033

#제출 시각아이디문제언어결과실행 시간메모리
176033mcdx9524Bigger segments (IZhO19_segments)C++14
100 / 100
122 ms14224 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); int rand(int l, int r) { return uniform_int_distribution <int> (l, r) (rnd); } const int inf = 1e9 + 7; void solve() { int n; cin >> n; vector <int> a(n + 1, 0); vector <ll> pref(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> a[i]; pref[i] = a[i] + pref[i - 1]; } vector <pair <int, ll> > dp(n + 1, {0, inf}); dp[0] = {0, 0}; for (int i = 0; i <= n; i++) { if (i >= 1) { ll sum = a[i]; if (dp[i - 1].first > dp[i].first) { dp[i].first = dp[i - 1].first; dp[i].second = dp[i - 1].second + a[i]; } else if (dp[i - 1].first == dp[i].first) { dp[i].second = min(dp[i].second, dp[i - 1].second + a[i]); } } int l = i + 1, r = n; int ans = -1; while (l <= r) { int m = (l + r) / 2; if (pref[m] - pref[i] >= dp[i].second) { ans = m; r = m - 1; } else { l = m + 1; } } if (ans == -1) { continue; } ll sum = pref[ans] - pref[i]; if (sum >= dp[i].second) { if (dp[i].first + 1 > dp[ans].first) { dp[ans].first = dp[i].first + 1; dp[ans].second = sum; } else if (dp[i].first + 1 == dp[ans].first) { dp[ans].second = min(dp[ans].second, sum); } } } cout << dp[n].first << '\n'; } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(0); cin.tie(0); int test_cnt = 1; //cin >> test_cnt; while (test_cnt--) { solve(); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

segments.cpp: In function 'void solve()':
segments.cpp:28:16: warning: unused variable 'sum' [-Wunused-variable]
             ll sum = a[i];
                ^~~
#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...