이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int dp[5002][5002], sum[5002], n, pref[5002];
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
sum[i] = sum[i - 1] + a;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++)
pref[j] = max(pref[j - 1], dp[j][i - 1]);
int matches = 0;
int ind = i - 1, best = pref[i - 1];
for (int j = i; j <= n; j++) {
dp[i][j] = best;
while (ind > 0 && sum[j] - sum[i - 1] > sum[i - 1] - sum[ind])
ind--;
if (ind && sum[j] - sum[i - 1] == sum[i - 1] - sum[ind]) {
matches++;
best = max(best, matches + pref[ind]);
}
}
}
int mx = 0;
for (int i = 1; i <= n; i++)
mx = max(mx, dp[i][n]);
cout << mx << "\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... |