Submission #338899

# Submission time Handle Problem Language Result Execution time Memory
338899 2020-12-24T07:27:31 Z nandonathaniel Bigger segments (IZhO19_segments) C++14
27 / 100
1500 ms 71532 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=3005;

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;
}
# Verdict Execution time Memory Grader output
1 Correct 36 ms 71148 KB Output is correct
2 Correct 36 ms 71148 KB Output is correct
3 Correct 36 ms 71148 KB Output is correct
4 Correct 36 ms 71148 KB Output is correct
5 Correct 36 ms 71148 KB Output is correct
6 Correct 36 ms 71148 KB Output is correct
7 Correct 36 ms 71148 KB Output is correct
8 Correct 36 ms 71148 KB Output is correct
9 Correct 36 ms 71148 KB Output is correct
10 Correct 36 ms 71148 KB Output is correct
11 Correct 37 ms 71148 KB Output is correct
12 Correct 36 ms 71148 KB Output is correct
13 Correct 36 ms 71148 KB Output is correct
14 Correct 37 ms 71148 KB Output is correct
15 Correct 37 ms 71168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 71148 KB Output is correct
2 Correct 36 ms 71148 KB Output is correct
3 Correct 36 ms 71148 KB Output is correct
4 Correct 36 ms 71148 KB Output is correct
5 Correct 36 ms 71148 KB Output is correct
6 Correct 36 ms 71148 KB Output is correct
7 Correct 36 ms 71148 KB Output is correct
8 Correct 36 ms 71148 KB Output is correct
9 Correct 36 ms 71148 KB Output is correct
10 Correct 36 ms 71148 KB Output is correct
11 Correct 37 ms 71148 KB Output is correct
12 Correct 36 ms 71148 KB Output is correct
13 Correct 36 ms 71148 KB Output is correct
14 Correct 37 ms 71148 KB Output is correct
15 Correct 37 ms 71168 KB Output is correct
16 Correct 50 ms 71148 KB Output is correct
17 Correct 51 ms 71148 KB Output is correct
18 Correct 54 ms 71276 KB Output is correct
19 Correct 57 ms 71168 KB Output is correct
20 Correct 67 ms 71148 KB Output is correct
21 Correct 51 ms 71148 KB Output is correct
22 Correct 46 ms 71148 KB Output is correct
23 Correct 43 ms 71532 KB Output is correct
24 Correct 54 ms 71148 KB Output is correct
25 Correct 55 ms 71276 KB Output is correct
26 Correct 67 ms 71148 KB Output is correct
27 Correct 56 ms 71148 KB Output is correct
28 Correct 54 ms 71148 KB Output is correct
29 Correct 67 ms 71148 KB Output is correct
30 Correct 65 ms 71324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 71148 KB Output is correct
2 Correct 36 ms 71148 KB Output is correct
3 Correct 36 ms 71148 KB Output is correct
4 Correct 36 ms 71148 KB Output is correct
5 Correct 36 ms 71148 KB Output is correct
6 Correct 36 ms 71148 KB Output is correct
7 Correct 36 ms 71148 KB Output is correct
8 Correct 36 ms 71148 KB Output is correct
9 Correct 36 ms 71148 KB Output is correct
10 Correct 36 ms 71148 KB Output is correct
11 Correct 37 ms 71148 KB Output is correct
12 Correct 36 ms 71148 KB Output is correct
13 Correct 36 ms 71148 KB Output is correct
14 Correct 37 ms 71148 KB Output is correct
15 Correct 37 ms 71168 KB Output is correct
16 Correct 50 ms 71148 KB Output is correct
17 Correct 51 ms 71148 KB Output is correct
18 Correct 54 ms 71276 KB Output is correct
19 Correct 57 ms 71168 KB Output is correct
20 Correct 67 ms 71148 KB Output is correct
21 Correct 51 ms 71148 KB Output is correct
22 Correct 46 ms 71148 KB Output is correct
23 Correct 43 ms 71532 KB Output is correct
24 Correct 54 ms 71148 KB Output is correct
25 Correct 55 ms 71276 KB Output is correct
26 Correct 67 ms 71148 KB Output is correct
27 Correct 56 ms 71148 KB Output is correct
28 Correct 54 ms 71148 KB Output is correct
29 Correct 67 ms 71148 KB Output is correct
30 Correct 65 ms 71324 KB Output is correct
31 Correct 732 ms 71276 KB Output is correct
32 Correct 714 ms 71404 KB Output is correct
33 Correct 777 ms 71404 KB Output is correct
34 Correct 962 ms 71276 KB Output is correct
35 Execution timed out 1542 ms 71308 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 71148 KB Output is correct
2 Correct 36 ms 71148 KB Output is correct
3 Correct 36 ms 71148 KB Output is correct
4 Correct 36 ms 71148 KB Output is correct
5 Correct 36 ms 71148 KB Output is correct
6 Correct 36 ms 71148 KB Output is correct
7 Correct 36 ms 71148 KB Output is correct
8 Correct 36 ms 71148 KB Output is correct
9 Correct 36 ms 71148 KB Output is correct
10 Correct 36 ms 71148 KB Output is correct
11 Correct 37 ms 71148 KB Output is correct
12 Correct 36 ms 71148 KB Output is correct
13 Correct 36 ms 71148 KB Output is correct
14 Correct 37 ms 71148 KB Output is correct
15 Correct 37 ms 71168 KB Output is correct
16 Correct 50 ms 71148 KB Output is correct
17 Correct 51 ms 71148 KB Output is correct
18 Correct 54 ms 71276 KB Output is correct
19 Correct 57 ms 71168 KB Output is correct
20 Correct 67 ms 71148 KB Output is correct
21 Correct 51 ms 71148 KB Output is correct
22 Correct 46 ms 71148 KB Output is correct
23 Correct 43 ms 71532 KB Output is correct
24 Correct 54 ms 71148 KB Output is correct
25 Correct 55 ms 71276 KB Output is correct
26 Correct 67 ms 71148 KB Output is correct
27 Correct 56 ms 71148 KB Output is correct
28 Correct 54 ms 71148 KB Output is correct
29 Correct 67 ms 71148 KB Output is correct
30 Correct 65 ms 71324 KB Output is correct
31 Correct 732 ms 71276 KB Output is correct
32 Correct 714 ms 71404 KB Output is correct
33 Correct 777 ms 71404 KB Output is correct
34 Correct 962 ms 71276 KB Output is correct
35 Execution timed out 1542 ms 71308 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 71148 KB Output is correct
2 Correct 36 ms 71148 KB Output is correct
3 Correct 36 ms 71148 KB Output is correct
4 Correct 36 ms 71148 KB Output is correct
5 Correct 36 ms 71148 KB Output is correct
6 Correct 36 ms 71148 KB Output is correct
7 Correct 36 ms 71148 KB Output is correct
8 Correct 36 ms 71148 KB Output is correct
9 Correct 36 ms 71148 KB Output is correct
10 Correct 36 ms 71148 KB Output is correct
11 Correct 37 ms 71148 KB Output is correct
12 Correct 36 ms 71148 KB Output is correct
13 Correct 36 ms 71148 KB Output is correct
14 Correct 37 ms 71148 KB Output is correct
15 Correct 37 ms 71168 KB Output is correct
16 Correct 50 ms 71148 KB Output is correct
17 Correct 51 ms 71148 KB Output is correct
18 Correct 54 ms 71276 KB Output is correct
19 Correct 57 ms 71168 KB Output is correct
20 Correct 67 ms 71148 KB Output is correct
21 Correct 51 ms 71148 KB Output is correct
22 Correct 46 ms 71148 KB Output is correct
23 Correct 43 ms 71532 KB Output is correct
24 Correct 54 ms 71148 KB Output is correct
25 Correct 55 ms 71276 KB Output is correct
26 Correct 67 ms 71148 KB Output is correct
27 Correct 56 ms 71148 KB Output is correct
28 Correct 54 ms 71148 KB Output is correct
29 Correct 67 ms 71148 KB Output is correct
30 Correct 65 ms 71324 KB Output is correct
31 Correct 732 ms 71276 KB Output is correct
32 Correct 714 ms 71404 KB Output is correct
33 Correct 777 ms 71404 KB Output is correct
34 Correct 962 ms 71276 KB Output is correct
35 Execution timed out 1542 ms 71308 KB Time limit exceeded
36 Halted 0 ms 0 KB -