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;
#define x first
#define y second
#define sz(a) a.size()
typedef long long ll;
const int N = 5e3 + 7;
int a[N];
int dp[N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
int cnt = 0;
int cur = i;
int sa = 0;
int sb = 0;
for (int k = i - 1; k >= 0; k++) {
sa += a[k];
while (cur <= j && sb < sa) {
sb += a[cur];
cur++;
}
dp[i][j] = max(dp[i][j], dp[k][i - 1] + cnt);
if (sa == sb && cur <= j)
cnt++;
}
}
}
int ans = 0;
for (int i = 0; i < n; i++)
ans = max(ans, dp[i][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... |