#include<bits/stdc++.h>
using namespace std;
const int MAXN=3005;
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
long long dp[MAXN][MAXN],pref[MAXN],tree[4*MAXN],lazy[4*MAXN];
int a[MAXN];
void updatenode(int now,int L,int R,int val){
tree[now]=((R-L+1))*val;
lazy[now]=val;
}
void pushdown(int now,int L,int R){
if(lazy[now]==-1)return;
int mid=(L+R)/2;
updatenode(2*now,L,mid,lazy[now]);
updatenode(2*now+1,mid+1,R,lazy[now]);
lazy[now]=-1;
}
int query(int now,int L,int R,int x,int y){
if(L>=x && R<=y)return tree[now];
if(L>y || R<x)return 0;
pushdown(now,L,R);
int mid=(L+R)/2;
return query(2*now,L,mid,x,y)+query(2*now+1,mid+1,R,x,y);
}
void update(int now,int L,int R,int x,int y,int val){
if(L>y || R<x)return;
if(L>=x && R<=y){
updatenode(now,L,R,val);
return;
}
int mid=(L+R)/2;
pushdown(now,L,R);
update(2*now,L,mid,x,y,val);
update(2*now+1,mid+1,R,x,y,val);
tree[now]=tree[2*now]+tree[2*now+1];
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i];
pref[i]=pref[i-1]+a[i];
}
memset(lazy,-1,sizeof(lazy));
memset(dp,-1,sizeof(dp));
dp[0][0]=0;
for(int j=1;j<=n;j++){
update(1,1,n,j,n,0);
for(int i=j;i<=n;i++){
if(dp[i-1][j-1]!=-1){
long long bil;
if(dp[i-1][j-1]==0)bil=2*pref[i-1];
else bil=2*pref[i-1]-pref[dp[i-1][j-1]-1];
int ki=i,ka=n,res=-1;
while(ki<=ka){
int mid=(ki+ka)/2;
if(pref[mid]>=bil){
res=mid;
ka=mid-1;
}
else ki=mid+1;
}
if(res!=-1)update(1,1,n,res,n,i);
}
dp[i][j]=query(1,1,n,i,i);
if(dp[i][j]==0)dp[i][j]=-1;
}
}
for(int j=n;j>=1;j--){
if(dp[n][j]!=-1){
cout << j << '\n';
break;
}
}
return 0;
}
Compilation message
segments.cpp:5: warning: ignoring #pragma GCC option [-Wunknown-pragmas]
5 | #pragma GCC option("arch=native","tune=native","no-zero-upper")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
71148 KB |
Output is correct |
2 |
Correct |
44 ms |
71148 KB |
Output is correct |
3 |
Correct |
38 ms |
71168 KB |
Output is correct |
4 |
Correct |
37 ms |
71148 KB |
Output is correct |
5 |
Correct |
36 ms |
71148 KB |
Output is correct |
6 |
Correct |
37 ms |
71148 KB |
Output is correct |
7 |
Correct |
38 ms |
71148 KB |
Output is correct |
8 |
Correct |
37 ms |
71148 KB |
Output is correct |
9 |
Correct |
37 ms |
71148 KB |
Output is correct |
10 |
Correct |
37 ms |
71148 KB |
Output is correct |
11 |
Correct |
37 ms |
71148 KB |
Output is correct |
12 |
Correct |
37 ms |
71148 KB |
Output is correct |
13 |
Correct |
40 ms |
71148 KB |
Output is correct |
14 |
Correct |
38 ms |
71148 KB |
Output is correct |
15 |
Correct |
37 ms |
71148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
71148 KB |
Output is correct |
2 |
Correct |
44 ms |
71148 KB |
Output is correct |
3 |
Correct |
38 ms |
71168 KB |
Output is correct |
4 |
Correct |
37 ms |
71148 KB |
Output is correct |
5 |
Correct |
36 ms |
71148 KB |
Output is correct |
6 |
Correct |
37 ms |
71148 KB |
Output is correct |
7 |
Correct |
38 ms |
71148 KB |
Output is correct |
8 |
Correct |
37 ms |
71148 KB |
Output is correct |
9 |
Correct |
37 ms |
71148 KB |
Output is correct |
10 |
Correct |
37 ms |
71148 KB |
Output is correct |
11 |
Correct |
37 ms |
71148 KB |
Output is correct |
12 |
Correct |
37 ms |
71148 KB |
Output is correct |
13 |
Correct |
40 ms |
71148 KB |
Output is correct |
14 |
Correct |
38 ms |
71148 KB |
Output is correct |
15 |
Correct |
37 ms |
71148 KB |
Output is correct |
16 |
Correct |
48 ms |
71148 KB |
Output is correct |
17 |
Correct |
49 ms |
71148 KB |
Output is correct |
18 |
Correct |
54 ms |
71148 KB |
Output is correct |
19 |
Correct |
58 ms |
71276 KB |
Output is correct |
20 |
Correct |
63 ms |
71148 KB |
Output is correct |
21 |
Correct |
52 ms |
71148 KB |
Output is correct |
22 |
Correct |
55 ms |
71148 KB |
Output is correct |
23 |
Correct |
41 ms |
71148 KB |
Output is correct |
24 |
Correct |
51 ms |
71148 KB |
Output is correct |
25 |
Correct |
50 ms |
71148 KB |
Output is correct |
26 |
Correct |
62 ms |
71148 KB |
Output is correct |
27 |
Correct |
64 ms |
71148 KB |
Output is correct |
28 |
Correct |
62 ms |
71148 KB |
Output is correct |
29 |
Correct |
62 ms |
71148 KB |
Output is correct |
30 |
Correct |
63 ms |
71148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
71148 KB |
Output is correct |
2 |
Correct |
44 ms |
71148 KB |
Output is correct |
3 |
Correct |
38 ms |
71168 KB |
Output is correct |
4 |
Correct |
37 ms |
71148 KB |
Output is correct |
5 |
Correct |
36 ms |
71148 KB |
Output is correct |
6 |
Correct |
37 ms |
71148 KB |
Output is correct |
7 |
Correct |
38 ms |
71148 KB |
Output is correct |
8 |
Correct |
37 ms |
71148 KB |
Output is correct |
9 |
Correct |
37 ms |
71148 KB |
Output is correct |
10 |
Correct |
37 ms |
71148 KB |
Output is correct |
11 |
Correct |
37 ms |
71148 KB |
Output is correct |
12 |
Correct |
37 ms |
71148 KB |
Output is correct |
13 |
Correct |
40 ms |
71148 KB |
Output is correct |
14 |
Correct |
38 ms |
71148 KB |
Output is correct |
15 |
Correct |
37 ms |
71148 KB |
Output is correct |
16 |
Correct |
48 ms |
71148 KB |
Output is correct |
17 |
Correct |
49 ms |
71148 KB |
Output is correct |
18 |
Correct |
54 ms |
71148 KB |
Output is correct |
19 |
Correct |
58 ms |
71276 KB |
Output is correct |
20 |
Correct |
63 ms |
71148 KB |
Output is correct |
21 |
Correct |
52 ms |
71148 KB |
Output is correct |
22 |
Correct |
55 ms |
71148 KB |
Output is correct |
23 |
Correct |
41 ms |
71148 KB |
Output is correct |
24 |
Correct |
51 ms |
71148 KB |
Output is correct |
25 |
Correct |
50 ms |
71148 KB |
Output is correct |
26 |
Correct |
62 ms |
71148 KB |
Output is correct |
27 |
Correct |
64 ms |
71148 KB |
Output is correct |
28 |
Correct |
62 ms |
71148 KB |
Output is correct |
29 |
Correct |
62 ms |
71148 KB |
Output is correct |
30 |
Correct |
63 ms |
71148 KB |
Output is correct |
31 |
Correct |
677 ms |
71364 KB |
Output is correct |
32 |
Correct |
691 ms |
71276 KB |
Output is correct |
33 |
Correct |
681 ms |
71276 KB |
Output is correct |
34 |
Correct |
958 ms |
71300 KB |
Output is correct |
35 |
Correct |
1446 ms |
71276 KB |
Output is correct |
36 |
Correct |
725 ms |
71404 KB |
Output is correct |
37 |
Correct |
458 ms |
71404 KB |
Output is correct |
38 |
Correct |
328 ms |
71452 KB |
Output is correct |
39 |
Correct |
685 ms |
71284 KB |
Output is correct |
40 |
Correct |
652 ms |
71404 KB |
Output is correct |
41 |
Correct |
1419 ms |
71284 KB |
Output is correct |
42 |
Correct |
1239 ms |
71404 KB |
Output is correct |
43 |
Correct |
793 ms |
71276 KB |
Output is correct |
44 |
Correct |
1432 ms |
71292 KB |
Output is correct |
45 |
Correct |
1347 ms |
71404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
71148 KB |
Output is correct |
2 |
Correct |
44 ms |
71148 KB |
Output is correct |
3 |
Correct |
38 ms |
71168 KB |
Output is correct |
4 |
Correct |
37 ms |
71148 KB |
Output is correct |
5 |
Correct |
36 ms |
71148 KB |
Output is correct |
6 |
Correct |
37 ms |
71148 KB |
Output is correct |
7 |
Correct |
38 ms |
71148 KB |
Output is correct |
8 |
Correct |
37 ms |
71148 KB |
Output is correct |
9 |
Correct |
37 ms |
71148 KB |
Output is correct |
10 |
Correct |
37 ms |
71148 KB |
Output is correct |
11 |
Correct |
37 ms |
71148 KB |
Output is correct |
12 |
Correct |
37 ms |
71148 KB |
Output is correct |
13 |
Correct |
40 ms |
71148 KB |
Output is correct |
14 |
Correct |
38 ms |
71148 KB |
Output is correct |
15 |
Correct |
37 ms |
71148 KB |
Output is correct |
16 |
Correct |
48 ms |
71148 KB |
Output is correct |
17 |
Correct |
49 ms |
71148 KB |
Output is correct |
18 |
Correct |
54 ms |
71148 KB |
Output is correct |
19 |
Correct |
58 ms |
71276 KB |
Output is correct |
20 |
Correct |
63 ms |
71148 KB |
Output is correct |
21 |
Correct |
52 ms |
71148 KB |
Output is correct |
22 |
Correct |
55 ms |
71148 KB |
Output is correct |
23 |
Correct |
41 ms |
71148 KB |
Output is correct |
24 |
Correct |
51 ms |
71148 KB |
Output is correct |
25 |
Correct |
50 ms |
71148 KB |
Output is correct |
26 |
Correct |
62 ms |
71148 KB |
Output is correct |
27 |
Correct |
64 ms |
71148 KB |
Output is correct |
28 |
Correct |
62 ms |
71148 KB |
Output is correct |
29 |
Correct |
62 ms |
71148 KB |
Output is correct |
30 |
Correct |
63 ms |
71148 KB |
Output is correct |
31 |
Correct |
677 ms |
71364 KB |
Output is correct |
32 |
Correct |
691 ms |
71276 KB |
Output is correct |
33 |
Correct |
681 ms |
71276 KB |
Output is correct |
34 |
Correct |
958 ms |
71300 KB |
Output is correct |
35 |
Correct |
1446 ms |
71276 KB |
Output is correct |
36 |
Correct |
725 ms |
71404 KB |
Output is correct |
37 |
Correct |
458 ms |
71404 KB |
Output is correct |
38 |
Correct |
328 ms |
71452 KB |
Output is correct |
39 |
Correct |
685 ms |
71284 KB |
Output is correct |
40 |
Correct |
652 ms |
71404 KB |
Output is correct |
41 |
Correct |
1419 ms |
71284 KB |
Output is correct |
42 |
Correct |
1239 ms |
71404 KB |
Output is correct |
43 |
Correct |
793 ms |
71276 KB |
Output is correct |
44 |
Correct |
1432 ms |
71292 KB |
Output is correct |
45 |
Correct |
1347 ms |
71404 KB |
Output is correct |
46 |
Runtime error |
134 ms |
144620 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
71148 KB |
Output is correct |
2 |
Correct |
44 ms |
71148 KB |
Output is correct |
3 |
Correct |
38 ms |
71168 KB |
Output is correct |
4 |
Correct |
37 ms |
71148 KB |
Output is correct |
5 |
Correct |
36 ms |
71148 KB |
Output is correct |
6 |
Correct |
37 ms |
71148 KB |
Output is correct |
7 |
Correct |
38 ms |
71148 KB |
Output is correct |
8 |
Correct |
37 ms |
71148 KB |
Output is correct |
9 |
Correct |
37 ms |
71148 KB |
Output is correct |
10 |
Correct |
37 ms |
71148 KB |
Output is correct |
11 |
Correct |
37 ms |
71148 KB |
Output is correct |
12 |
Correct |
37 ms |
71148 KB |
Output is correct |
13 |
Correct |
40 ms |
71148 KB |
Output is correct |
14 |
Correct |
38 ms |
71148 KB |
Output is correct |
15 |
Correct |
37 ms |
71148 KB |
Output is correct |
16 |
Correct |
48 ms |
71148 KB |
Output is correct |
17 |
Correct |
49 ms |
71148 KB |
Output is correct |
18 |
Correct |
54 ms |
71148 KB |
Output is correct |
19 |
Correct |
58 ms |
71276 KB |
Output is correct |
20 |
Correct |
63 ms |
71148 KB |
Output is correct |
21 |
Correct |
52 ms |
71148 KB |
Output is correct |
22 |
Correct |
55 ms |
71148 KB |
Output is correct |
23 |
Correct |
41 ms |
71148 KB |
Output is correct |
24 |
Correct |
51 ms |
71148 KB |
Output is correct |
25 |
Correct |
50 ms |
71148 KB |
Output is correct |
26 |
Correct |
62 ms |
71148 KB |
Output is correct |
27 |
Correct |
64 ms |
71148 KB |
Output is correct |
28 |
Correct |
62 ms |
71148 KB |
Output is correct |
29 |
Correct |
62 ms |
71148 KB |
Output is correct |
30 |
Correct |
63 ms |
71148 KB |
Output is correct |
31 |
Correct |
677 ms |
71364 KB |
Output is correct |
32 |
Correct |
691 ms |
71276 KB |
Output is correct |
33 |
Correct |
681 ms |
71276 KB |
Output is correct |
34 |
Correct |
958 ms |
71300 KB |
Output is correct |
35 |
Correct |
1446 ms |
71276 KB |
Output is correct |
36 |
Correct |
725 ms |
71404 KB |
Output is correct |
37 |
Correct |
458 ms |
71404 KB |
Output is correct |
38 |
Correct |
328 ms |
71452 KB |
Output is correct |
39 |
Correct |
685 ms |
71284 KB |
Output is correct |
40 |
Correct |
652 ms |
71404 KB |
Output is correct |
41 |
Correct |
1419 ms |
71284 KB |
Output is correct |
42 |
Correct |
1239 ms |
71404 KB |
Output is correct |
43 |
Correct |
793 ms |
71276 KB |
Output is correct |
44 |
Correct |
1432 ms |
71292 KB |
Output is correct |
45 |
Correct |
1347 ms |
71404 KB |
Output is correct |
46 |
Runtime error |
134 ms |
144620 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
47 |
Halted |
0 ms |
0 KB |
- |