제출 #1132643

#제출 시각아이디문제언어결과실행 시간메모리
1132643JelalTkmBigger segments (IZhO19_segments)C++17
13 / 100
0 ms328 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC target ("sse4") using namespace std; #define int long long int const int N = 3e5 + 10; const int md = 1e9 + 7; const int INF = 1e9; int32_t main(int32_t argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; while (T--) { int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; vector<int> pref(n + 1); for (int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + a[i]; } vector<pair<int, int>> dp(n + 1); dp[1] = {a[1], 1}; for (int i = 2; i <= n; i++) { dp[i] = {dp[i - 1].first + a[i], dp[i - 1].second}; int l = 1, r = i + 1; while (r - l > 1) { int mid = (l + r) >> 1; if (pref[i] - pref[mid - 1] >= dp[mid - 1].first) l = mid; else r = mid; } if (pref[i] - pref[l - 1] >= dp[l - 1].first) { dp[i].first = pref[i] - pref[l - 1]; dp[i].second = dp[l - 1].second + 1; } } cout << dp[n].second << '\n'; } return 0; }
#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...