Submission #629021

#TimeUsernameProblemLanguageResultExecution timeMemory
629021bojackduyBigger segments (IZhO19_segments)C++14
13 / 100
42 ms1324 KiB
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef long long ll; const int N = 1e6 + 1; int n, res; int a[N]; int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<vi> dp(n + 1, vi(n + 1, -1e9)); for (int i = 1; i <= n; i++) dp[0][i] = 1; vector<ll> pre(n + 1, 0); for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { for (int k = 0; k <= j; k++) { int sum2 = pre[i] - pre[j]; int sum1 = pre[j] - pre[k]; if (sum1 <= sum2 && dp[k][j] > 0) { dp[j][i] = max(dp[j][i], dp[k][j] + 1); } } } } int res = 0; for (int i = 0; i <= n; i++) res = max(res, dp[i][n]); cout << res; 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...