이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define int long long
# define fi first
# define se second
using namespace std;
const int N = 5e3 + 7;
const int mod = 1e9 + 7;
int a[N], sum[N], ans, cnt, n;
map < int, int > used[N], dp[N];
int solve( int pos, int sm ) {
if ( pos == n + 1 ) {
return 0;
}
if ( used[pos][sm] ) {
return dp[pos][sm];
}
used[pos][sm] = 1;
int s = 0, mx = 0;
for ( int i = pos; i <= n; i++ ) {
s += a[i];
if ( s >= sm ) {
mx = max( mx, 1 + solve( i + 1, s ) );
}
}
dp[pos][sm] = mx;
return mx;
}
int32_t main() {
speed;
cin >> n;
for ( int i = 1; i <= n; i++ ) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
cout << solve( 1, 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... |