답안 #756346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
756346 2023-06-11T14:35:12 Z Fidan K개의 묶음 (IZhO14_blocks) C++17
53 / 100
1000 ms 6612 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(ll i=ll(a); i<ll(b); i++)
#define repn(i, a, b) for(ll i=ll(b)-1; i>=ll(a); i--)
#define pb push_back
#define si size()
#define ff first
#define ss second
#define be begin()
#define en end()
const ll N=(1e5)+1;
const ll K=101;
const ll inf=(1e8)+1;
vector<ll> v(N);
vector<ll> x(N, -1);
vector<ll> s;
vector<ll> dp1(N, inf), dp2(N, inf);
vector<ll> T(4*N, inf);
void upd(ll in, ll val, ll l, ll r, ll v1){
	if(l==r && r==in){
		T[v1]=val;
		return;
	}
	if(l>r) return;
	ll mid=(l+r)/2;
	if(in<=mid){
		upd(in, val, l, mid, 2*v1);
	}
	else{
		upd(in, val, mid+1, r, 2*v1+1);
	}
	T[v1]=min(T[2*v1], T[2*v1+1]);
}
ll que(ll l, ll r, ll tl, ll tr, ll v1){
	if(l>r) return inf;
	if(l==tl && r==tr) return T[v1];
	ll mid=(tl+tr)/2;
	return min(que(l, min(r, mid), tl, mid, 2*v1), que(max(mid+1, l), r, mid+1, tr, 2*v1+1));
}
void solve(){
	ll n, k;
	cin>>n>>k;
	rep(i, 1, n+1){
		cin>>v[i];
	}
	ll o=0;
	s.pb(1);
	rep(i, 2, n+1){
		if(v[s[o]]>=v[i]){
			x[i]=s[o];
		}
		else{
			while(true){
				if(o<0) break;
				if(v[s[o]]>=v[i]) break;
				s.pop_back();
				o--;
			}
			if(o!=-1){
				x[i]=s[o];
			}
		}
		o++;
		s.pb(i);
	}
	dp1[1]=v[1];
	upd(1, dp1[1], 1, n, 1);
	rep(i, 2, n+1){
		dp1[i]=max(dp1[i-1], v[i]);
		upd(i, dp1[i], 1, n, 1);
	}
	rep(j, 2, k+1){
		rep(i, 1, n+1){
			dp2[i]=inf;
			if(i<j){
				continue;
			}
			else{
				dp2[i]=v[i]+dp1[i-1];
				if(x[i]==-1){
					dp2[i]=min(dp2[i], v[i]+que(1, i-1, 1, n, 1));
				}
				else if(x[i]==i-1){
					dp2[i]=min(dp2[i], dp2[x[i]]);
				}
				else{
					dp2[i]=min(dp2[i], v[i]+que(x[i]+1, i-1, 1, n, 1));
					dp2[i]=min(dp2[i], dp2[x[i]]);
				}
			}
		}
		rep(i, 1, n+1){
			upd(i, dp2[i], 1, n, 1);
		}
		swap(dp1, dp2);
	}
	cout<<dp1[n];
}
int main(){
	ios_base::sync_with_stdio();
	cin.tie(0);
	ll t=1;
	//~ cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 5 ms 6484 KB Output is correct
3 Correct 4 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6484 KB Output is correct
7 Correct 3 ms 6484 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6476 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Correct 3 ms 6484 KB Output is correct
13 Correct 3 ms 6484 KB Output is correct
14 Correct 4 ms 6484 KB Output is correct
15 Correct 3 ms 6484 KB Output is correct
16 Correct 3 ms 6484 KB Output is correct
17 Correct 4 ms 6484 KB Output is correct
18 Correct 4 ms 6484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 4 ms 6484 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6484 KB Output is correct
7 Correct 3 ms 6484 KB Output is correct
8 Correct 4 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 4 ms 6484 KB Output is correct
11 Correct 4 ms 6484 KB Output is correct
12 Correct 4 ms 6484 KB Output is correct
13 Correct 4 ms 6612 KB Output is correct
14 Correct 3 ms 6484 KB Output is correct
15 Correct 3 ms 6484 KB Output is correct
16 Correct 3 ms 6484 KB Output is correct
17 Correct 3 ms 6484 KB Output is correct
18 Correct 5 ms 6484 KB Output is correct
19 Correct 3 ms 6484 KB Output is correct
20 Correct 3 ms 6484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 5 ms 6484 KB Output is correct
3 Correct 4 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6484 KB Output is correct
7 Correct 3 ms 6484 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6476 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Correct 3 ms 6484 KB Output is correct
13 Correct 3 ms 6484 KB Output is correct
14 Correct 4 ms 6484 KB Output is correct
15 Correct 3 ms 6484 KB Output is correct
16 Correct 3 ms 6484 KB Output is correct
17 Correct 4 ms 6484 KB Output is correct
18 Correct 4 ms 6484 KB Output is correct
19 Correct 4 ms 6484 KB Output is correct
20 Correct 4 ms 6484 KB Output is correct
21 Correct 3 ms 6484 KB Output is correct
22 Correct 3 ms 6484 KB Output is correct
23 Correct 3 ms 6484 KB Output is correct
24 Correct 3 ms 6484 KB Output is correct
25 Correct 3 ms 6484 KB Output is correct
26 Correct 4 ms 6484 KB Output is correct
27 Correct 3 ms 6484 KB Output is correct
28 Correct 4 ms 6484 KB Output is correct
29 Correct 4 ms 6484 KB Output is correct
30 Correct 4 ms 6484 KB Output is correct
31 Correct 4 ms 6612 KB Output is correct
32 Correct 3 ms 6484 KB Output is correct
33 Correct 3 ms 6484 KB Output is correct
34 Correct 3 ms 6484 KB Output is correct
35 Correct 3 ms 6484 KB Output is correct
36 Correct 5 ms 6484 KB Output is correct
37 Correct 3 ms 6484 KB Output is correct
38 Correct 3 ms 6484 KB Output is correct
39 Correct 3 ms 6484 KB Output is correct
40 Correct 3 ms 6532 KB Output is correct
41 Correct 3 ms 6484 KB Output is correct
42 Correct 3 ms 6572 KB Output is correct
43 Correct 3 ms 6484 KB Output is correct
44 Correct 3 ms 6484 KB Output is correct
45 Correct 3 ms 6484 KB Output is correct
46 Correct 3 ms 6484 KB Output is correct
47 Correct 3 ms 6484 KB Output is correct
48 Correct 3 ms 6484 KB Output is correct
49 Correct 3 ms 6484 KB Output is correct
50 Correct 3 ms 6484 KB Output is correct
51 Correct 3 ms 6592 KB Output is correct
52 Correct 3 ms 6484 KB Output is correct
53 Correct 4 ms 6484 KB Output is correct
54 Correct 4 ms 6484 KB Output is correct
55 Correct 3 ms 6484 KB Output is correct
56 Correct 4 ms 6484 KB Output is correct
57 Correct 3 ms 6484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 5 ms 6484 KB Output is correct
3 Correct 4 ms 6484 KB Output is correct
4 Correct 3 ms 6484 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6484 KB Output is correct
7 Correct 3 ms 6484 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6476 KB Output is correct
10 Correct 3 ms 6484 KB Output is correct
11 Correct 3 ms 6484 KB Output is correct
12 Correct 3 ms 6484 KB Output is correct
13 Correct 3 ms 6484 KB Output is correct
14 Correct 4 ms 6484 KB Output is correct
15 Correct 3 ms 6484 KB Output is correct
16 Correct 3 ms 6484 KB Output is correct
17 Correct 4 ms 6484 KB Output is correct
18 Correct 4 ms 6484 KB Output is correct
19 Correct 4 ms 6484 KB Output is correct
20 Correct 4 ms 6484 KB Output is correct
21 Correct 3 ms 6484 KB Output is correct
22 Correct 3 ms 6484 KB Output is correct
23 Correct 3 ms 6484 KB Output is correct
24 Correct 3 ms 6484 KB Output is correct
25 Correct 3 ms 6484 KB Output is correct
26 Correct 4 ms 6484 KB Output is correct
27 Correct 3 ms 6484 KB Output is correct
28 Correct 4 ms 6484 KB Output is correct
29 Correct 4 ms 6484 KB Output is correct
30 Correct 4 ms 6484 KB Output is correct
31 Correct 4 ms 6612 KB Output is correct
32 Correct 3 ms 6484 KB Output is correct
33 Correct 3 ms 6484 KB Output is correct
34 Correct 3 ms 6484 KB Output is correct
35 Correct 3 ms 6484 KB Output is correct
36 Correct 5 ms 6484 KB Output is correct
37 Correct 3 ms 6484 KB Output is correct
38 Correct 3 ms 6484 KB Output is correct
39 Correct 3 ms 6484 KB Output is correct
40 Correct 3 ms 6532 KB Output is correct
41 Correct 3 ms 6484 KB Output is correct
42 Correct 3 ms 6572 KB Output is correct
43 Correct 3 ms 6484 KB Output is correct
44 Correct 3 ms 6484 KB Output is correct
45 Correct 3 ms 6484 KB Output is correct
46 Correct 3 ms 6484 KB Output is correct
47 Correct 3 ms 6484 KB Output is correct
48 Correct 3 ms 6484 KB Output is correct
49 Correct 3 ms 6484 KB Output is correct
50 Correct 3 ms 6484 KB Output is correct
51 Correct 3 ms 6592 KB Output is correct
52 Correct 3 ms 6484 KB Output is correct
53 Correct 4 ms 6484 KB Output is correct
54 Correct 4 ms 6484 KB Output is correct
55 Correct 3 ms 6484 KB Output is correct
56 Correct 4 ms 6484 KB Output is correct
57 Correct 3 ms 6484 KB Output is correct
58 Correct 52 ms 6484 KB Output is correct
59 Correct 28 ms 6568 KB Output is correct
60 Correct 78 ms 6564 KB Output is correct
61 Correct 670 ms 6564 KB Output is correct
62 Execution timed out 1070 ms 6484 KB Time limit exceeded
63 Halted 0 ms 0 KB -