Submission #990901

#TimeUsernameProblemLanguageResultExecution timeMemory
990901ToniBBigger segments (IZhO19_segments)C++17
37 / 100
1555 ms9160 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][2]; ll pre[N]; ll sum(int i, int j) { if (i) return pre[j] - pre[i - 1]; return pre[j]; } bool cmp(pii x, pii y) { if (x.X == y.X) return x.Y < y.Y; return x.X > y.X; } 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]; dp[0][0] = dp[0][1] = {1, a[0]}; for (int i = 1; i < n; ++i) { vector<pii> v = {{1, pre[i]}}; for (int j = 0; j < i; ++j) { for (int k = 0; k < 2; ++k) { if (sum(j + 1, i) >= dp[j][k].Y) { v.push_back({dp[j][k].X + 1, sum(j + 1, i)}); } } } sort(v.begin(), v.end(), cmp); dp[i][0] = v[0]; dp[i][1] = v[0]; for (int j = 1; j < (int)v.size(); ++j) { if (v[j].X != v[0].X) { dp[i][1] = v[j]; break; } } } cout << dp[n - 1][0].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...