#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define rep(i, a, b) for(ll i = a; i < ll(b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
int main() {
//cin.sync_with_stdio(0); cin.tie(0);
//cin.exceptions(cin.failbit);
ll n;
cin>>n;
vi a(n);
rep(i,0,n) cin>>a[i];
vector<vi> dp(n,vi(n+1,-1e9));
rep(i,0,n+1) dp[0][i] = 0;
rep(i,1,n){
ll sum = 0;
rep(j,i,n){
sum += a[j];
ll sum2 = 0;
for(ll k = i-1;k>=0;k--){
sum2 += a[k];
if(sum2>sum) break;
dp[i][j] = max(dp[i][j],dp[k][i-1]+1);
}
}
}
/*
rep(i,0,n) {
rep(j,0,n) {
printf("%3d ",dp[i][j]);
}
printf("\n");
}*/
rep(i,0,n) {
rep(j,0,n) {
if(j<n-1 && dp[i][j]>=0 && dp[i][j+1]>=0){
assert(dp[i][j]==dp[i][j+1]);
/*if(dp[i][j]!=dp[i][j+1]){
cout<<"("<<i<<","<<j<<"): "<<dp[i][j]<<endl;
cout<<"("<<i<<","<<j+1<<"): "<<dp[i][j+1]<<endl;
}*/
}
}
}
ll ans = 0;
rep(i,0,n) ans = max(ans,dp[i][n-1]);
cout<<ans+1<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
1 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
1 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
23 ms |
2296 KB |
Output is correct |
17 |
Correct |
23 ms |
2268 KB |
Output is correct |
18 |
Correct |
23 ms |
2268 KB |
Output is correct |
19 |
Correct |
18 ms |
2296 KB |
Output is correct |
20 |
Correct |
23 ms |
2296 KB |
Output is correct |
21 |
Correct |
39 ms |
2296 KB |
Output is correct |
22 |
Correct |
14 ms |
1656 KB |
Output is correct |
23 |
Correct |
7 ms |
1016 KB |
Output is correct |
24 |
Correct |
25 ms |
2296 KB |
Output is correct |
25 |
Correct |
23 ms |
2240 KB |
Output is correct |
26 |
Correct |
33 ms |
2296 KB |
Output is correct |
27 |
Correct |
17 ms |
2296 KB |
Output is correct |
28 |
Correct |
28 ms |
2460 KB |
Output is correct |
29 |
Correct |
26 ms |
2296 KB |
Output is correct |
30 |
Correct |
22 ms |
2296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
1 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
23 ms |
2296 KB |
Output is correct |
17 |
Correct |
23 ms |
2268 KB |
Output is correct |
18 |
Correct |
23 ms |
2268 KB |
Output is correct |
19 |
Correct |
18 ms |
2296 KB |
Output is correct |
20 |
Correct |
23 ms |
2296 KB |
Output is correct |
21 |
Correct |
39 ms |
2296 KB |
Output is correct |
22 |
Correct |
14 ms |
1656 KB |
Output is correct |
23 |
Correct |
7 ms |
1016 KB |
Output is correct |
24 |
Correct |
25 ms |
2296 KB |
Output is correct |
25 |
Correct |
23 ms |
2240 KB |
Output is correct |
26 |
Correct |
33 ms |
2296 KB |
Output is correct |
27 |
Correct |
17 ms |
2296 KB |
Output is correct |
28 |
Correct |
28 ms |
2460 KB |
Output is correct |
29 |
Correct |
26 ms |
2296 KB |
Output is correct |
30 |
Correct |
22 ms |
2296 KB |
Output is correct |
31 |
Execution timed out |
1529 ms |
70904 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
1 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
23 ms |
2296 KB |
Output is correct |
17 |
Correct |
23 ms |
2268 KB |
Output is correct |
18 |
Correct |
23 ms |
2268 KB |
Output is correct |
19 |
Correct |
18 ms |
2296 KB |
Output is correct |
20 |
Correct |
23 ms |
2296 KB |
Output is correct |
21 |
Correct |
39 ms |
2296 KB |
Output is correct |
22 |
Correct |
14 ms |
1656 KB |
Output is correct |
23 |
Correct |
7 ms |
1016 KB |
Output is correct |
24 |
Correct |
25 ms |
2296 KB |
Output is correct |
25 |
Correct |
23 ms |
2240 KB |
Output is correct |
26 |
Correct |
33 ms |
2296 KB |
Output is correct |
27 |
Correct |
17 ms |
2296 KB |
Output is correct |
28 |
Correct |
28 ms |
2460 KB |
Output is correct |
29 |
Correct |
26 ms |
2296 KB |
Output is correct |
30 |
Correct |
22 ms |
2296 KB |
Output is correct |
31 |
Execution timed out |
1529 ms |
70904 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
1 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
23 ms |
2296 KB |
Output is correct |
17 |
Correct |
23 ms |
2268 KB |
Output is correct |
18 |
Correct |
23 ms |
2268 KB |
Output is correct |
19 |
Correct |
18 ms |
2296 KB |
Output is correct |
20 |
Correct |
23 ms |
2296 KB |
Output is correct |
21 |
Correct |
39 ms |
2296 KB |
Output is correct |
22 |
Correct |
14 ms |
1656 KB |
Output is correct |
23 |
Correct |
7 ms |
1016 KB |
Output is correct |
24 |
Correct |
25 ms |
2296 KB |
Output is correct |
25 |
Correct |
23 ms |
2240 KB |
Output is correct |
26 |
Correct |
33 ms |
2296 KB |
Output is correct |
27 |
Correct |
17 ms |
2296 KB |
Output is correct |
28 |
Correct |
28 ms |
2460 KB |
Output is correct |
29 |
Correct |
26 ms |
2296 KB |
Output is correct |
30 |
Correct |
22 ms |
2296 KB |
Output is correct |
31 |
Execution timed out |
1529 ms |
70904 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |