Submission #688629

# Submission time Handle Problem Language Result Execution time Memory
688629 2023-01-27T21:34:56 Z luka1234 K blocks (IZhO14_blocks) C++14
53 / 100
1000 ms 159000 KB
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
ll n,m;
ll a[100001];
ll dp[100001][101];
ll t[101][400001];
ll marc[100001];
void update(ll v,ll tl,ll tr,ll pos,ll x,ll ind){
	if(tl==tr){
		t[ind][v]=x;
	}
	else{
		ll m=(tl+tr)/2;
		if(pos<=m){
			update(2*v,tl,m,pos,x,ind);
		}
		else{
			update(2*v+1,m+1,tr,pos,x,ind);
		}
		t[ind][v]=min(t[ind][2*v],t[ind][2*v+1]);
	}
}
ll get(ll v,ll tl,ll tr,ll l,ll r,ll ind){
	if(tr<l||tl>r){
		return 1e18;
	}
	if(tl>=l&&tr<=r){
		return t[ind][v];
	}
	ll m=(tl+tr)/2;
	ll f1=get(2*v,tl,m,l,r,ind);
	ll f2=get(2*v+1,m+1,tr,l,r,ind);
	ll f=min(f1,f2);
	return f;
}
void make(){
	stack<ll> st;
	for(ll k=n;k>=1;k--){
		while(!st.empty()&&a[k]>a[st.top()]){
			int f=a[st.top()];
			marc[st.top()]=k;
			st.pop();
		}
		st.push(k);
	}
}
int main(){
	for(ll i=0;i<=100000;i++){
		for(ll j=0;j<=100;j++){
			dp[i][j]=1e18;
		}
	}
	cin>>n>>m;
	ll mx=0;
	for(ll k=1;k<=n;k++){
		cin>>a[k];
		mx=max(mx,a[k]);
		dp[k][1]=mx;
		update(1,1,n,k,mx,1);
	}
	make();
	for(ll k=2;k<=m;k++){
		for(ll i=k;i<=n;i++){
			ll f=marc[i];
			f=max(f,k-1);
			ll mn1=dp[i-1][k-1]+a[i];
			ll mn=get(1,1,n,f,i-1,k-1);
			mn=mn+a[i];
			ll f1=dp[f][k];
			mn=min(mn,f1);
			mn=min(mn,mn1);
			dp[i][k]=mn;
			update(1,1,n,i,mn,k);
		}
	}
	cout<<dp[n][m];
    return 0;
}

Compilation message

blocks.cpp: In function 'void make()':
blocks.cpp:48:8: warning: unused variable 'f' [-Wunused-variable]
   48 |    int f=a[st.top()];
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 35 ms 79308 KB Output is correct
2 Correct 35 ms 79296 KB Output is correct
3 Correct 41 ms 79260 KB Output is correct
4 Correct 34 ms 79316 KB Output is correct
5 Correct 35 ms 79492 KB Output is correct
6 Correct 35 ms 79292 KB Output is correct
7 Correct 36 ms 79360 KB Output is correct
8 Correct 36 ms 79392 KB Output is correct
9 Correct 40 ms 79312 KB Output is correct
10 Correct 38 ms 79276 KB Output is correct
11 Correct 42 ms 79376 KB Output is correct
12 Correct 39 ms 79332 KB Output is correct
13 Correct 38 ms 79316 KB Output is correct
14 Correct 37 ms 79376 KB Output is correct
15 Correct 36 ms 79292 KB Output is correct
16 Correct 36 ms 79356 KB Output is correct
17 Correct 38 ms 79340 KB Output is correct
18 Correct 40 ms 79408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 79316 KB Output is correct
2 Correct 43 ms 79364 KB Output is correct
3 Correct 40 ms 79312 KB Output is correct
4 Correct 41 ms 79376 KB Output is correct
5 Correct 41 ms 79344 KB Output is correct
6 Correct 38 ms 79340 KB Output is correct
7 Correct 38 ms 79336 KB Output is correct
8 Correct 37 ms 79356 KB Output is correct
9 Correct 36 ms 79328 KB Output is correct
10 Correct 40 ms 79300 KB Output is correct
11 Correct 44 ms 79296 KB Output is correct
12 Correct 40 ms 79336 KB Output is correct
13 Correct 36 ms 79308 KB Output is correct
14 Correct 37 ms 79368 KB Output is correct
15 Correct 37 ms 79324 KB Output is correct
16 Correct 37 ms 79516 KB Output is correct
17 Correct 36 ms 79480 KB Output is correct
18 Correct 37 ms 79436 KB Output is correct
19 Correct 38 ms 79416 KB Output is correct
20 Correct 39 ms 79484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 79308 KB Output is correct
2 Correct 35 ms 79296 KB Output is correct
3 Correct 41 ms 79260 KB Output is correct
4 Correct 34 ms 79316 KB Output is correct
5 Correct 35 ms 79492 KB Output is correct
6 Correct 35 ms 79292 KB Output is correct
7 Correct 36 ms 79360 KB Output is correct
8 Correct 36 ms 79392 KB Output is correct
9 Correct 40 ms 79312 KB Output is correct
10 Correct 38 ms 79276 KB Output is correct
11 Correct 42 ms 79376 KB Output is correct
12 Correct 39 ms 79332 KB Output is correct
13 Correct 38 ms 79316 KB Output is correct
14 Correct 37 ms 79376 KB Output is correct
15 Correct 36 ms 79292 KB Output is correct
16 Correct 36 ms 79356 KB Output is correct
17 Correct 38 ms 79340 KB Output is correct
18 Correct 40 ms 79408 KB Output is correct
19 Correct 43 ms 79316 KB Output is correct
20 Correct 43 ms 79364 KB Output is correct
21 Correct 40 ms 79312 KB Output is correct
22 Correct 41 ms 79376 KB Output is correct
23 Correct 41 ms 79344 KB Output is correct
24 Correct 38 ms 79340 KB Output is correct
25 Correct 38 ms 79336 KB Output is correct
26 Correct 37 ms 79356 KB Output is correct
27 Correct 36 ms 79328 KB Output is correct
28 Correct 40 ms 79300 KB Output is correct
29 Correct 44 ms 79296 KB Output is correct
30 Correct 40 ms 79336 KB Output is correct
31 Correct 36 ms 79308 KB Output is correct
32 Correct 37 ms 79368 KB Output is correct
33 Correct 37 ms 79324 KB Output is correct
34 Correct 37 ms 79516 KB Output is correct
35 Correct 36 ms 79480 KB Output is correct
36 Correct 37 ms 79436 KB Output is correct
37 Correct 38 ms 79416 KB Output is correct
38 Correct 39 ms 79484 KB Output is correct
39 Correct 41 ms 79768 KB Output is correct
40 Correct 37 ms 79308 KB Output is correct
41 Correct 36 ms 79292 KB Output is correct
42 Correct 46 ms 79292 KB Output is correct
43 Correct 39 ms 79316 KB Output is correct
44 Correct 37 ms 79272 KB Output is correct
45 Correct 42 ms 79248 KB Output is correct
46 Correct 42 ms 79316 KB Output is correct
47 Correct 36 ms 79316 KB Output is correct
48 Correct 37 ms 79312 KB Output is correct
49 Correct 37 ms 79280 KB Output is correct
50 Correct 37 ms 79348 KB Output is correct
51 Correct 36 ms 79564 KB Output is correct
52 Correct 36 ms 79572 KB Output is correct
53 Correct 44 ms 80248 KB Output is correct
54 Correct 49 ms 80340 KB Output is correct
55 Correct 39 ms 79876 KB Output is correct
56 Correct 38 ms 80260 KB Output is correct
57 Correct 38 ms 80344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 79308 KB Output is correct
2 Correct 35 ms 79296 KB Output is correct
3 Correct 41 ms 79260 KB Output is correct
4 Correct 34 ms 79316 KB Output is correct
5 Correct 35 ms 79492 KB Output is correct
6 Correct 35 ms 79292 KB Output is correct
7 Correct 36 ms 79360 KB Output is correct
8 Correct 36 ms 79392 KB Output is correct
9 Correct 40 ms 79312 KB Output is correct
10 Correct 38 ms 79276 KB Output is correct
11 Correct 42 ms 79376 KB Output is correct
12 Correct 39 ms 79332 KB Output is correct
13 Correct 38 ms 79316 KB Output is correct
14 Correct 37 ms 79376 KB Output is correct
15 Correct 36 ms 79292 KB Output is correct
16 Correct 36 ms 79356 KB Output is correct
17 Correct 38 ms 79340 KB Output is correct
18 Correct 40 ms 79408 KB Output is correct
19 Correct 43 ms 79316 KB Output is correct
20 Correct 43 ms 79364 KB Output is correct
21 Correct 40 ms 79312 KB Output is correct
22 Correct 41 ms 79376 KB Output is correct
23 Correct 41 ms 79344 KB Output is correct
24 Correct 38 ms 79340 KB Output is correct
25 Correct 38 ms 79336 KB Output is correct
26 Correct 37 ms 79356 KB Output is correct
27 Correct 36 ms 79328 KB Output is correct
28 Correct 40 ms 79300 KB Output is correct
29 Correct 44 ms 79296 KB Output is correct
30 Correct 40 ms 79336 KB Output is correct
31 Correct 36 ms 79308 KB Output is correct
32 Correct 37 ms 79368 KB Output is correct
33 Correct 37 ms 79324 KB Output is correct
34 Correct 37 ms 79516 KB Output is correct
35 Correct 36 ms 79480 KB Output is correct
36 Correct 37 ms 79436 KB Output is correct
37 Correct 38 ms 79416 KB Output is correct
38 Correct 39 ms 79484 KB Output is correct
39 Correct 41 ms 79768 KB Output is correct
40 Correct 37 ms 79308 KB Output is correct
41 Correct 36 ms 79292 KB Output is correct
42 Correct 46 ms 79292 KB Output is correct
43 Correct 39 ms 79316 KB Output is correct
44 Correct 37 ms 79272 KB Output is correct
45 Correct 42 ms 79248 KB Output is correct
46 Correct 42 ms 79316 KB Output is correct
47 Correct 36 ms 79316 KB Output is correct
48 Correct 37 ms 79312 KB Output is correct
49 Correct 37 ms 79280 KB Output is correct
50 Correct 37 ms 79348 KB Output is correct
51 Correct 36 ms 79564 KB Output is correct
52 Correct 36 ms 79572 KB Output is correct
53 Correct 44 ms 80248 KB Output is correct
54 Correct 49 ms 80340 KB Output is correct
55 Correct 39 ms 79876 KB Output is correct
56 Correct 38 ms 80260 KB Output is correct
57 Correct 38 ms 80344 KB Output is correct
58 Correct 104 ms 86224 KB Output is correct
59 Correct 59 ms 81532 KB Output is correct
60 Correct 176 ms 87668 KB Output is correct
61 Execution timed out 1042 ms 159000 KB Time limit exceeded
62 Halted 0 ms 0 KB -