이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define bug(x) cout << #x << " " << x << endl;
const int maxn = 5e3 + 10;
const int maxm = 1e7;
int dp[maxn][maxn], v[maxn], suf[maxn];
int main(){
int n; cin >> n;
for( int i = 1; i <= n; i++ ) cin >> v[i];
int resp = 0;
for( int j = n - 1; j >= 1; j-- ){
// bug(j);
// for( int k = 0; k <= n; k++ ) cout << dp[j][k] << " "; cout << endl;
for( int k = n; k > j; k-- ) suf[k] = max( dp[j][k], suf[k + 1] );
int k = j + 1, cont = 0;
int sumL = 0, sumR = v[k];
int pref = dp[j][k];
for( int i = j - 1; i >= 0; i-- ){
// bug(i);
// bug(sumL);
while( k < n && sumR <= sumL ){
if( sumL == sumR ) cont++;
sumR += v[++k];
pref = max( pref, dp[j][k] + cont );
}
// bug(k) ;
// bug(sumR);
// bug(cont);
dp[i][j] = max( pref, suf[k + 1] + cont );
resp = max( resp, dp[i][j] );
sumL += v[i + 1];
}
}
cout << resp << endl;
}
# | 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... |