제출 #337248

#제출 시각아이디문제언어결과실행 시간메모리
337248boykutBigger segments (IZhO19_segments)C++14
13 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 500001 int a[MAXN], dp[MAXN]; int prefsum[MAXN], sm[MAXN]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; prefsum[i] = prefsum[i - 1] + a[i]; } priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; q.push({0, 0}); int tmp = 0; for (int i = 1; i <= n; i++) { while (!q.empty() && q.top().first <= prefsum[i]) { if (dp[q.top().second] > dp[tmp]) { tmp = q.top().second; } else if (dp[q.top().second] == dp[tmp]) { tmp = max(tmp, q.top().second); } q.pop(); } q.push({prefsum[i] * 2 - prefsum[tmp], i}); dp[i] = dp[tmp] + 1; } cout << dp[n] << '\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...