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;
const int N = 5005;
int dp[N][N], ndp[N][N];
void initDP(int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = ndp[i][j] = 0;
}
}
return ;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
initDP(n);
array<int, N> a;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
for (int prev = 1; prev < n; prev++) {
int sumLeft = 0, sumRight = 0;
int x = prev - 1;
int pt = 0;
for (int i = prev + 1; i < n; i++) {
dp[prev][i] = max(dp[prev][i], dp[prev][i - 1]);
sumRight += a[i - 1];
while (x > 0 && sumLeft < sumRight) {
sumLeft += a[x];
x--;
}
if (sumLeft == sumRight) {
pt += 1;
}
dp[prev][i] = max(dp[prev][i], ndp[x][prev - 1] + pt);
dp[prev][i] = max(dp[prev][i], dp[x][prev - 1] + pt);
ndp[prev][i] = max(ndp[prev][i], ndp[prev - 1][i]);
ndp[prev][i] = max(ndp[prev][i], dp[prev][i]);
}
ans = max(ans, dp[prev][n - 1]);
}
cout << ans << '\n';
return 0;
}
# | 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... |