Submission #629023

#TimeUsernameProblemLanguageResultExecution timeMemory
629023bojackduyBigger segments (IZhO19_segments)C++14
27 / 100
1593 ms70820 KiB
#include <bits/stdc++.h> #define int long long 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[i][0] = 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 = 1; k < j; k++) { int sum2 = pre[i] - pre[j - 1]; int sum1 = pre[j - 1] - pre[k - 1]; if (sum1 <= sum2) { dp[i][j - 1] = max(dp[i][j - 1], dp[j - 1][k - 1] + 1); } } } } cout << *max_element(dp[n].begin(), dp[n].end()); 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...