// #pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
// #pragma GCC target("avx2")
#define int long long
using namespace std;
#define MAXN 85
bool seen[MAXN][MAXN][MAXN][2];
int cached[MAXN][MAXN][MAXN][2];
int arr[MAXN];
int presum[MAXN];
int n;
int dp(int l, int r, int pos, bool right) {
if(l != -1 && r != -1) {
if(seen[l][r][pos][right]) return cached[l][r][pos][right];
seen[l][r][pos][right] = true;
}
if(l == 0 && r == 1 && pos == 3) {
int a = 0;
}
int maxval = 0;
if(pos != n -1) maxval = dp(r + 1, pos, pos + 1, 1 - right);
if(l == -1 || r == -1) {
if(pos != n -1) maxval = max(maxval, dp(-1, -1, pos + 1, right));
}else {
int a = presum[pos + 1] - presum[r + 1];
bool works = false;
for(int i = r; i > l; i--) {
int dist = presum[r+1] - presum[i];
if(dist == a) {
works = true;
}
if(dist> a) {
break;
}
}
if(works) {
if(pos != n -1) maxval = max(maxval, dp(l, r, pos + 1, right) + 1);
// else maxval = 1;
}else {
if(pos != n -1) maxval = max(maxval, dp(l, r, pos + 1, right));
}
}
return cached[l][r][pos][right] = maxval;
}
signed main() {
cin >> n;
for(int i = 0; i < n; i++) {
cin >> arr[i];
}
presum[0] = 0;
for(int i = 1; i <= n; i++) {
presum[i] = presum[i-1] + arr[i-1];
}
cout<<dp(-1, -1,0,true);
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... |