/**
* author: wxhtzdy
* created: 29.06.2022 21:43:16
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> pref(n + 1);
for (int i = 0; i < n; i++) {
pref[i + 1] = pref[i] + a[i];
}
vector<vector<int>> dp(n + 1, vector<int>(n + 1));
for (int l = 1; l <= n; l++) {
map<long long, int> pos;
for (int i = 1; i < l; i++) {
pos[pref[l - 1] - pref[i - 1]] = i;
}
vector<int> pref_mx(n + 1);
for (int i = 0; i < l; i++) {
pref_mx[i + 1] = max(pref_mx[i], dp[i][l - 1]);
}
int ft = 0;
for (int r = l; r <= n; r++) {
dp[l][r] = dp[l][r - 1];
if (l < r) {
long long s = pref[r - 1] - pref[l - 1];
if (pos.count(s)) {
ft += 1;
dp[l][r] = max(dp[l][r], ft + pref_mx[pos[s]]);
}
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans = max(ans, dp[i][n]);
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1236 KB |
Output is correct |
2 |
Incorrect |
11 ms |
1340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |