# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344622 | Nurlykhan | Bigger segments (IZhO19_segments) | C++17 | 200 ms | 35820 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
using namespace std;
const int N = (int)3000 + 10;
const int mod = (int)1e9 + 7;
int n;
int a[N];
ll pref[N];
ll get_sum(int l, int r) {
return pref[r] - pref[l - 1];
}
int dp[N][N];
int main() {
// freopen("in.txt", "r", stdin);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
pref[i] = pref[i - 1] + a[i];
}
for (int l = 0; l <= n; l++) {
for (int r = 0; r <= n; r++) {
dp[l][r] = -mod;
}
}
dp[1][1] = 1;
for (int l = 1; l <= n; l++) {
for (int r = l; r <= n; r++) {
dp[l][r + 1] = max(dp[l][r + 1], dp[l][r]);
int lo = r + 1, hi = n, ans = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (get_sum(l, r) > get_sum(r + 1, mid)) {
lo = mid + 1;
} else {
ans = mid;
hi = mid - 1;
}
}
if (ans != -1)
dp[r + 1][ans] = max(dp[r + 1][ans], dp[l][r] + 1);
}
}
int ans = 0;
for (int l = 1; l <= n; l++)
ans = max(ans, dp[l][n]);
cout << ans;
return 0;
}
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... |