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 int int64_t
#define z(X, Y) (X = max(X, Y))
signed main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
int d[N]; for(int &i : d) cin >> i;
int dp[N][N] {}, ans {};
for(int i = 1; i < N; ++i) {
int s0 {}, s1 {}, k = i - 1, cnt {};
for(int j = i, f {}; j < N; ++j) {
for(; k >= 0 && s0 + d[k] < s1 + d[j]; --k)
if((s0 += d[k]) == s1) ++cnt, f = k;
s1 += d[j];
if(f > 0) z(dp[i][j], dp[f-1][i-1] + cnt);
z(ans, z(dp[i][j], dp[i][j-1]));
}
for(int j = 1; j <= i; ++j)
z(dp[j][i], dp[j-1][i]);
}
cout << ans;
}
# | 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... |