# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
701651 | lto5 | Bigger segments (IZhO19_segments) | C++14 | 427 ms | 262144 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>
using namespace std;
int a[100005];
int64_t s[100005];
int f[5005][5005];
int suf[5005][5005];
int64_t get(int l, int r) {
return s[r] - s[l - 1];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define task "a"
if (fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
memset(f, -1, sizeof(f));
for (int i = 1; i <= n; i++) {
int k = i;
for (int j = i; j >= 2; j--) {
while (k - 1 >= 1 && get(j, i) >= get(k - 1, j - 1)) {
k--;
}
if (k >= 1 && k <= j - 1 && get(j, i) >= get(k, j - 1)) {
if (suf[j - 1][k] != -1) f[i][j] = suf[j - 1][k] + 1;
}
}
f[i][1] = 1;
suf[i][i + 1] = -1;
for (int j = i; j >= 1; j--) {
suf[i][j] = max(suf[i][j + 1], f[i][j]);
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
ans = max(ans, f[i][j]);
}
}
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... |