#include <bits/stdc++.h>
#pragma GCC optimize "Ofast,unroll-loops"
#pragma GCC target "avx2"
using namespace std;
const int MAXN = 5005;
void solve(){
int n; cin >> n;
vector<vector<int>> dp(n+1, vector<int>(n+1, 0)), pref(n+1, vector<int>(n+1, 0));
vector<int> arr(n+1);
for(int i=1;i<=n;i++) cin >> arr[i];
for(int l=2;l<=n;l++){
int ptr=l-1, sum=0, curr=0, tot=0;
for(int r=l;r<=n;r++){
dp[l][r]=max(dp[l][r-1], pref[ptr][l-1]+tot);
sum+=arr[r];
while(ptr>1 && curr<sum) curr+=arr[ptr--];
tot+=(curr==sum);
}
pref[0][l]=dp[0][l];
for(int i=1;i<=l;i++) pref[i][l]=max(dp[i][l], pref[i-1][l]);
}
int ans=pref[n][n];
cout << ans << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int tt=1;
//~ cin >> tt;
while(tt--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2396 KB |
Output is correct |
2 |
Correct |
3 ms |
2456 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2396 KB |
Output is correct |
5 |
Correct |
3 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2396 KB |
Output is correct |
7 |
Correct |
3 ms |
2296 KB |
Output is correct |
8 |
Correct |
3 ms |
2396 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2396 KB |
Output is correct |
12 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
2396 KB |
Output is correct |
22 |
Correct |
3 ms |
2456 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
24 |
Correct |
4 ms |
2396 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2396 KB |
Output is correct |
27 |
Correct |
3 ms |
2296 KB |
Output is correct |
28 |
Correct |
3 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
3 ms |
2396 KB |
Output is correct |
31 |
Correct |
3 ms |
2396 KB |
Output is correct |
32 |
Correct |
3 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2392 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
4 ms |
2396 KB |
Output is correct |
36 |
Correct |
3 ms |
2396 KB |
Output is correct |
37 |
Correct |
3 ms |
2396 KB |
Output is correct |
38 |
Correct |
3 ms |
2396 KB |
Output is correct |
39 |
Correct |
4 ms |
2396 KB |
Output is correct |
40 |
Correct |
3 ms |
2396 KB |
Output is correct |
41 |
Correct |
4 ms |
2396 KB |
Output is correct |
42 |
Correct |
3 ms |
2460 KB |
Output is correct |
43 |
Correct |
4 ms |
2396 KB |
Output is correct |
44 |
Correct |
3 ms |
2460 KB |
Output is correct |
45 |
Correct |
4 ms |
2460 KB |
Output is correct |
46 |
Correct |
3 ms |
2392 KB |
Output is correct |
47 |
Correct |
4 ms |
2396 KB |
Output is correct |
48 |
Correct |
3 ms |
2396 KB |
Output is correct |
49 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
2396 KB |
Output is correct |
22 |
Correct |
3 ms |
2456 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
24 |
Correct |
4 ms |
2396 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2396 KB |
Output is correct |
27 |
Correct |
3 ms |
2296 KB |
Output is correct |
28 |
Correct |
3 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
3 ms |
2396 KB |
Output is correct |
31 |
Correct |
3 ms |
2396 KB |
Output is correct |
32 |
Correct |
3 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2392 KB |
Output is correct |
34 |
Correct |
3 ms |
2396 KB |
Output is correct |
35 |
Correct |
4 ms |
2396 KB |
Output is correct |
36 |
Correct |
3 ms |
2396 KB |
Output is correct |
37 |
Correct |
3 ms |
2396 KB |
Output is correct |
38 |
Correct |
3 ms |
2396 KB |
Output is correct |
39 |
Correct |
4 ms |
2396 KB |
Output is correct |
40 |
Correct |
3 ms |
2396 KB |
Output is correct |
41 |
Correct |
4 ms |
2396 KB |
Output is correct |
42 |
Correct |
3 ms |
2460 KB |
Output is correct |
43 |
Correct |
4 ms |
2396 KB |
Output is correct |
44 |
Correct |
3 ms |
2460 KB |
Output is correct |
45 |
Correct |
4 ms |
2460 KB |
Output is correct |
46 |
Correct |
3 ms |
2392 KB |
Output is correct |
47 |
Correct |
4 ms |
2396 KB |
Output is correct |
48 |
Correct |
3 ms |
2396 KB |
Output is correct |
49 |
Correct |
3 ms |
2396 KB |
Output is correct |
50 |
Correct |
316 ms |
196448 KB |
Output is correct |
51 |
Correct |
284 ms |
196588 KB |
Output is correct |
52 |
Correct |
304 ms |
196384 KB |
Output is correct |
53 |
Correct |
286 ms |
196460 KB |
Output is correct |
54 |
Correct |
288 ms |
196432 KB |
Output is correct |
55 |
Correct |
282 ms |
196432 KB |
Output is correct |
56 |
Correct |
297 ms |
196588 KB |
Output is correct |
57 |
Correct |
307 ms |
196432 KB |
Output is correct |
58 |
Correct |
312 ms |
196588 KB |
Output is correct |
59 |
Correct |
327 ms |
196432 KB |
Output is correct |
60 |
Correct |
318 ms |
196596 KB |
Output is correct |
61 |
Correct |
313 ms |
196600 KB |
Output is correct |
62 |
Correct |
291 ms |
196440 KB |
Output is correct |
63 |
Correct |
307 ms |
196688 KB |
Output is correct |
64 |
Correct |
294 ms |
196600 KB |
Output is correct |
65 |
Correct |
276 ms |
196424 KB |
Output is correct |
66 |
Correct |
308 ms |
196432 KB |
Output is correct |
67 |
Correct |
293 ms |
196428 KB |
Output is correct |
68 |
Correct |
320 ms |
196688 KB |
Output is correct |
69 |
Correct |
287 ms |
196592 KB |
Output is correct |
70 |
Correct |
295 ms |
196436 KB |
Output is correct |
71 |
Correct |
331 ms |
196396 KB |
Output is correct |
72 |
Correct |
305 ms |
196436 KB |
Output is correct |