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"
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;
void _(){
int n; cin >> n;
int ar[n+5];
for(int i=1;i<=n;i++) cin >> ar[i];
int pre[n+5][n+5],dp[n+5][n+5];
memset(dp,0,sizeof(dp));
memset(pre,0,sizeof(pre));
for(int i = 1; i <= n; i++){
int p = i, cur = 0, cost = 0, _p = i - 1, cur2 = 0;
vector<int> suf(n+5,0);
while(p <= n){
while(_p > 1 && cur2 < cur) cur2 += ar[_p--];
if(cur > 0 && cur == cur2) cost++;
cur += ar[p];
// cout << i << ' ' << p << ' ' << cost << '\n';
dp[i][p] = max(dp[i][p], pre[_p][i-1] + cost);
suf[p] = max(pre[_p][i-1] + cost, suf[p]);
p++;
}
for(int j = i; j <= n; j++) suf[j] = max(suf[j - 1], suf[j]);
for(int j = i; j <= n; j++) dp[i][j] = max(dp[i][j], suf[j]);
for(int j = 1; j <= i; j++) pre[j][i] = max(pre[j-1][i], dp[j][i]);
}
int ans = 0;
for(int i=1;i<=n;i++) ans = max(ans, dp[i][n]);
cout << ans << '\n';
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int tc=1;//cin >> tc;
while(tc--) _();
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... |