#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 5010;
int dp[N][N];
int D[N];
struct Node{
int val;
int lzy;
};
Node T[N * 4 + 16];
void push(int node, int cl, int cr){
T[node].val += T[node].lzy;
if(cl != cr){
T[node * 2].lzy += T[node].lzy;
T[node * 2 + 1].lzy += T[node].lzy;
}
T[node].lzy = 0;
}
void update(int node, int cl, int cr, int tl, int tr, int v){
push(node, cl, cr);
if(cr < tl || cl > tr) return;
if(cl >= tl && cr <= tr){
T[node].lzy = v;
push(node, cl, cr);
return;
}
int mid = (cl + cr) / 2;
update(node * 2, cl, mid, tl, tr, v);
update(node * 2 + 1, mid + 1, cr, tl, tr, v);
T[node].val = max(T[node * 2].val, T[node * 2 + 1].val);
}
void build(int node, int cl, int cr){
T[node].val = 0;
T[node].lzy = 0;
if(cl == cr) return ;
int mid = (cl + cr) / 2;
build(node * 2, cl, mid);
build(node * 2 + 1, mid + 1, cr);
}
int main(){
fastIO;
//freopen("in.txt","r",stdin);
int n;
cin >> n;
for(int i = 1; i <= n; i ++ ){
cin >> D[i];
}
int pp;
int cum;
int cur;
int outp = 0;
for(int cut = 2; cut <= n; cut ++ ){
build(1, 1, n );
for(int j = cut - 1; j >= 1; j -- ){
update(1, 1, n, j, j, dp[j][cut - 1]);
}
cur = 0;
cum = 0;
pp = cut;
for(int go = cut; go <= n; go ++ ){
dp[cut][go] = T[1].val;
if(go == n)
outp = max(outp, dp[cut][go]);
cur += D[go];
while(pp > 1 && cum < cur){
pp --;
cum += D[pp];
}
if(cum == cur){
update(1, 1, n, 1, pp - 1, +1);
}
}
}
cout << outp << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
2760 KB |
Output is correct |
2 |
Correct |
34 ms |
2756 KB |
Output is correct |
3 |
Correct |
32 ms |
2748 KB |
Output is correct |
4 |
Correct |
36 ms |
2804 KB |
Output is correct |
5 |
Correct |
34 ms |
2828 KB |
Output is correct |
6 |
Correct |
33 ms |
2700 KB |
Output is correct |
7 |
Correct |
33 ms |
2736 KB |
Output is correct |
8 |
Correct |
34 ms |
2740 KB |
Output is correct |
9 |
Correct |
36 ms |
2764 KB |
Output is correct |
10 |
Correct |
32 ms |
2788 KB |
Output is correct |
11 |
Correct |
33 ms |
2756 KB |
Output is correct |
12 |
Correct |
32 ms |
2796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
576 KB |
Output is correct |
21 |
Correct |
32 ms |
2760 KB |
Output is correct |
22 |
Correct |
34 ms |
2756 KB |
Output is correct |
23 |
Correct |
32 ms |
2748 KB |
Output is correct |
24 |
Correct |
36 ms |
2804 KB |
Output is correct |
25 |
Correct |
34 ms |
2828 KB |
Output is correct |
26 |
Correct |
33 ms |
2700 KB |
Output is correct |
27 |
Correct |
33 ms |
2736 KB |
Output is correct |
28 |
Correct |
34 ms |
2740 KB |
Output is correct |
29 |
Correct |
36 ms |
2764 KB |
Output is correct |
30 |
Correct |
32 ms |
2788 KB |
Output is correct |
31 |
Correct |
33 ms |
2756 KB |
Output is correct |
32 |
Correct |
32 ms |
2796 KB |
Output is correct |
33 |
Correct |
32 ms |
2704 KB |
Output is correct |
34 |
Correct |
32 ms |
2836 KB |
Output is correct |
35 |
Correct |
33 ms |
2740 KB |
Output is correct |
36 |
Correct |
33 ms |
2756 KB |
Output is correct |
37 |
Correct |
33 ms |
2756 KB |
Output is correct |
38 |
Correct |
33 ms |
2796 KB |
Output is correct |
39 |
Correct |
28 ms |
2720 KB |
Output is correct |
40 |
Correct |
26 ms |
2748 KB |
Output is correct |
41 |
Correct |
26 ms |
2768 KB |
Output is correct |
42 |
Correct |
27 ms |
2744 KB |
Output is correct |
43 |
Correct |
27 ms |
2732 KB |
Output is correct |
44 |
Correct |
27 ms |
2764 KB |
Output is correct |
45 |
Correct |
27 ms |
2816 KB |
Output is correct |
46 |
Correct |
27 ms |
2724 KB |
Output is correct |
47 |
Correct |
28 ms |
2836 KB |
Output is correct |
48 |
Correct |
27 ms |
2700 KB |
Output is correct |
49 |
Correct |
27 ms |
2712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
576 KB |
Output is correct |
21 |
Correct |
32 ms |
2760 KB |
Output is correct |
22 |
Correct |
34 ms |
2756 KB |
Output is correct |
23 |
Correct |
32 ms |
2748 KB |
Output is correct |
24 |
Correct |
36 ms |
2804 KB |
Output is correct |
25 |
Correct |
34 ms |
2828 KB |
Output is correct |
26 |
Correct |
33 ms |
2700 KB |
Output is correct |
27 |
Correct |
33 ms |
2736 KB |
Output is correct |
28 |
Correct |
34 ms |
2740 KB |
Output is correct |
29 |
Correct |
36 ms |
2764 KB |
Output is correct |
30 |
Correct |
32 ms |
2788 KB |
Output is correct |
31 |
Correct |
33 ms |
2756 KB |
Output is correct |
32 |
Correct |
32 ms |
2796 KB |
Output is correct |
33 |
Correct |
32 ms |
2704 KB |
Output is correct |
34 |
Correct |
32 ms |
2836 KB |
Output is correct |
35 |
Correct |
33 ms |
2740 KB |
Output is correct |
36 |
Correct |
33 ms |
2756 KB |
Output is correct |
37 |
Correct |
33 ms |
2756 KB |
Output is correct |
38 |
Correct |
33 ms |
2796 KB |
Output is correct |
39 |
Correct |
28 ms |
2720 KB |
Output is correct |
40 |
Correct |
26 ms |
2748 KB |
Output is correct |
41 |
Correct |
26 ms |
2768 KB |
Output is correct |
42 |
Correct |
27 ms |
2744 KB |
Output is correct |
43 |
Correct |
27 ms |
2732 KB |
Output is correct |
44 |
Correct |
27 ms |
2764 KB |
Output is correct |
45 |
Correct |
27 ms |
2816 KB |
Output is correct |
46 |
Correct |
27 ms |
2724 KB |
Output is correct |
47 |
Correct |
28 ms |
2836 KB |
Output is correct |
48 |
Correct |
27 ms |
2700 KB |
Output is correct |
49 |
Correct |
27 ms |
2712 KB |
Output is correct |
50 |
Execution timed out |
1095 ms |
40988 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |