#include <bits/stdc++.h>
#include <random>
#define ll long long
#define int long long
#define fi first
#define se second
#define pb push_back
#define md ((l+r)>>1)
#define lf (id<<1)
#define rg ((id<<1)|1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,pii> ipii;
const int MAXN = 5e3+10;
const int MAXA = 1e6+10;
const int INF = 2e9+10;
const int LOG = 30;
const int MOD = 1e9+7;
void chmx(int &a, int b){
a = max(a, b);
}
int n;
int a[MAXN], pr[MAXN], dp[MAXN][MAXN];
signed main() {
// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i];
}
for(int p=1; p<=n-1; p++){
pr[1] = dp[1][p];
for(int i=2; i<=p; i++){
pr[i] = max(pr[i-1], dp[i][p]);
}
int l = p, r = p+1, top = 0, bot = 0, cnt = -1;
while(l>=1 && r<=n){
if(top==bot){
cnt++;
chmx(dp[p+1][r], pr[l]+cnt); // max dp[...][l-1]
top += a[l--]; bot += a[r++];
} else if(top < bot){
top += a[l--];
} else if(top > bot){
bot += a[r++];
}
}
for(int i=p+1; i<=n; i++) chmx(dp[p][i], dp[p][i-1]);
}
int ANS = 0;
for(int i=1; i<=n; i++) ANS = max(ANS, dp[i][n]);
cout << ANS << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
2 ms |
3420 KB |
Output is correct |
5 |
Correct |
2 ms |
3420 KB |
Output is correct |
6 |
Correct |
3 ms |
3416 KB |
Output is correct |
7 |
Correct |
3 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
3 ms |
3420 KB |
Output is correct |
11 |
Correct |
3 ms |
3420 KB |
Output is correct |
12 |
Correct |
2 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
696 KB |
Output is correct |
21 |
Correct |
2 ms |
3420 KB |
Output is correct |
22 |
Correct |
2 ms |
3420 KB |
Output is correct |
23 |
Correct |
2 ms |
3420 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3420 KB |
Output is correct |
26 |
Correct |
3 ms |
3416 KB |
Output is correct |
27 |
Correct |
3 ms |
3420 KB |
Output is correct |
28 |
Correct |
2 ms |
3420 KB |
Output is correct |
29 |
Correct |
3 ms |
3420 KB |
Output is correct |
30 |
Correct |
3 ms |
3420 KB |
Output is correct |
31 |
Correct |
3 ms |
3420 KB |
Output is correct |
32 |
Correct |
2 ms |
3420 KB |
Output is correct |
33 |
Correct |
2 ms |
3420 KB |
Output is correct |
34 |
Correct |
2 ms |
3420 KB |
Output is correct |
35 |
Correct |
3 ms |
3252 KB |
Output is correct |
36 |
Correct |
2 ms |
3420 KB |
Output is correct |
37 |
Correct |
4 ms |
3420 KB |
Output is correct |
38 |
Correct |
3 ms |
3252 KB |
Output is correct |
39 |
Correct |
3 ms |
3416 KB |
Output is correct |
40 |
Correct |
3 ms |
3420 KB |
Output is correct |
41 |
Correct |
3 ms |
3420 KB |
Output is correct |
42 |
Correct |
2 ms |
3420 KB |
Output is correct |
43 |
Correct |
2 ms |
3420 KB |
Output is correct |
44 |
Correct |
3 ms |
3420 KB |
Output is correct |
45 |
Correct |
3 ms |
3420 KB |
Output is correct |
46 |
Correct |
3 ms |
3420 KB |
Output is correct |
47 |
Correct |
2 ms |
3420 KB |
Output is correct |
48 |
Correct |
2 ms |
3420 KB |
Output is correct |
49 |
Correct |
3 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
696 KB |
Output is correct |
21 |
Correct |
2 ms |
3420 KB |
Output is correct |
22 |
Correct |
2 ms |
3420 KB |
Output is correct |
23 |
Correct |
2 ms |
3420 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3420 KB |
Output is correct |
26 |
Correct |
3 ms |
3416 KB |
Output is correct |
27 |
Correct |
3 ms |
3420 KB |
Output is correct |
28 |
Correct |
2 ms |
3420 KB |
Output is correct |
29 |
Correct |
3 ms |
3420 KB |
Output is correct |
30 |
Correct |
3 ms |
3420 KB |
Output is correct |
31 |
Correct |
3 ms |
3420 KB |
Output is correct |
32 |
Correct |
2 ms |
3420 KB |
Output is correct |
33 |
Correct |
2 ms |
3420 KB |
Output is correct |
34 |
Correct |
2 ms |
3420 KB |
Output is correct |
35 |
Correct |
3 ms |
3252 KB |
Output is correct |
36 |
Correct |
2 ms |
3420 KB |
Output is correct |
37 |
Correct |
4 ms |
3420 KB |
Output is correct |
38 |
Correct |
3 ms |
3252 KB |
Output is correct |
39 |
Correct |
3 ms |
3416 KB |
Output is correct |
40 |
Correct |
3 ms |
3420 KB |
Output is correct |
41 |
Correct |
3 ms |
3420 KB |
Output is correct |
42 |
Correct |
2 ms |
3420 KB |
Output is correct |
43 |
Correct |
2 ms |
3420 KB |
Output is correct |
44 |
Correct |
3 ms |
3420 KB |
Output is correct |
45 |
Correct |
3 ms |
3420 KB |
Output is correct |
46 |
Correct |
3 ms |
3420 KB |
Output is correct |
47 |
Correct |
2 ms |
3420 KB |
Output is correct |
48 |
Correct |
2 ms |
3420 KB |
Output is correct |
49 |
Correct |
3 ms |
3420 KB |
Output is correct |
50 |
Correct |
161 ms |
117436 KB |
Output is correct |
51 |
Correct |
160 ms |
117328 KB |
Output is correct |
52 |
Correct |
160 ms |
117332 KB |
Output is correct |
53 |
Correct |
159 ms |
117444 KB |
Output is correct |
54 |
Correct |
180 ms |
117328 KB |
Output is correct |
55 |
Correct |
180 ms |
117328 KB |
Output is correct |
56 |
Correct |
198 ms |
117396 KB |
Output is correct |
57 |
Correct |
196 ms |
117332 KB |
Output is correct |
58 |
Correct |
186 ms |
117328 KB |
Output is correct |
59 |
Correct |
205 ms |
117392 KB |
Output is correct |
60 |
Correct |
186 ms |
117332 KB |
Output is correct |
61 |
Correct |
182 ms |
117328 KB |
Output is correct |
62 |
Correct |
192 ms |
117524 KB |
Output is correct |
63 |
Correct |
160 ms |
117328 KB |
Output is correct |
64 |
Correct |
190 ms |
117328 KB |
Output is correct |
65 |
Correct |
175 ms |
117376 KB |
Output is correct |
66 |
Correct |
170 ms |
117328 KB |
Output is correct |
67 |
Correct |
167 ms |
117416 KB |
Output is correct |
68 |
Correct |
186 ms |
117720 KB |
Output is correct |
69 |
Correct |
166 ms |
117332 KB |
Output is correct |
70 |
Correct |
189 ms |
117380 KB |
Output is correct |
71 |
Correct |
211 ms |
117472 KB |
Output is correct |
72 |
Correct |
202 ms |
117332 KB |
Output is correct |