# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
628050 | BackNoob | Bigger segments (IZhO19_segments) | C++14 | 1590 ms | 38228 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se se cond
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
const int mxN = 3227;
const int inf = 1e9 + 7;
const int infll = 1e18 + 7;
int n;
int a[mxN];
ll pre[mxN];
int dp[mxN][mxN];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("task.inp", "r", stdin);
//freopen("task.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++) dp[i][j] = -inf;
for(int i = 1; i <= n; i++) dp[0][i] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= i; j++) {
for(int k = 0; k <= j; k++) {
if(pre[i] - pre[j] >= pre[j] - pre[k] && dp[k][j] > 0) {
dp[j][i] = max(dp[j][i], dp[k][j] + 1);
}
}
}
}
int ans = 0;
for(int i = 0; i <= n; i++) ans= max(ans, dp[i][n]);
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |