제출 #990909

#제출 시각아이디문제언어결과실행 시간메모리
990909ToniBBigger segments (IZhO19_segments)C++17
37 / 100
1565 ms8628 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typedef pair<int, ll> pii; const int N = 5e5 + 2; int n, a[N]; pii dp[N]; ll pre[N]; set<pair<ll, pii> > s; pii cmp_dp(pii x, pii y) { if (x.X == y.X) { if (x.Y < y.Y) return x; return y; } if (x.X > y.X) return x; return y; } int main(){ cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; pre[0] = a[0]; for (int i = 1; i < n; ++i) pre[i] = a[i] + pre[i - 1]; for (int i = 0; i < n; ++i) { dp[i] = {1, pre[i]}; for (int j = 0; j < i; ++j) { if (pre[i] >= dp[j].Y + pre[j]) { dp[i] = cmp_dp(dp[i], {dp[j].X + 1, pre[i] - pre[j]}); } } // pii cur = {dp[i].X, pre[i]}; // pair<ll, pii> pt = {dp[i].Y + pre[i], cur}; // // auto it = s.lower_bound(pt); // if (it != s.end() && (*it)) } cout << dp[n - 1].X << "\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...