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 <stdio.h>
#include <string.h>
#define N 5000
#define N_ (1 << 13)
int max(int a, int b) { return a > b ? a : b; }
int ss[N_ * 2], pp[N_ * 2], n_;
void pul(int i) {
int l = i << 1, r = l | 1;
ss[i] = ss[l] + ss[r];
pp[i] = max(pp[l], ss[l] + pp[r]);
}
void update(int i, int x) {
i += n_;
pp[i] = ss[i] += x;
while (i > 1)
pul(i >>= 1);
}
int main() {
static int aa[N + 1], dp[N + 1][N + 1];
int n, i, j, k, ans;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &aa[i]);
aa[i] += aa[i - 1];
}
for (i = 1; i <= n; i++)
dp[0][i] = 0;
n_ = 1;
while (n_ < n)
n_ <<= 1;
for (j = 1; j <= n; j++) {
memset(ss, 0, n_ * 2 * sizeof *ss);
for (i = 0; i < j; i++) {
update(i, dp[i][j]);
if (i + 1 < n)
update(i + 1, -dp[i][j]);
}
for (k = j + 1, i = j - 1; k <= n; k++) {
dp[j][k] = pp[1];
while (i >= 0 && aa[i] + aa[k] > aa[j] * 2)
i--;
if (i >= 0 && aa[i] + aa[k] == aa[j] * 2)
update(0, 1), update(i, -1);
}
}
ans = 0;
for (i = 0; i < n; i++)
ans = max(ans, dp[i][n]);
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
cigle.c: In function 'main':
cigle.c:29:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
cigle.c:31:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# | 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... |