제출 #291326

#제출 시각아이디문제언어결과실행 시간메모리
291326HynDufK개의 묶음 (IZhO14_blocks)C++14
100 / 100
175 ms3872 KiB
#include <bits/stdc++.h> #define task "B" #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (l); i <= (r); ++i) #define Rep(i, r, l) for (int i = (r); i >= (l); --i) #define DB(X) { cerr << #X << " = " << (X) << '\n'; } #define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; } #define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; } #define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; } #define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';} #define SZ(x) ((int)(x).size()) #define pb push_back #define eb emplace_back #define pf push_front #define F first #define S second #define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a)); #define next ___next #define prev ___prev #define y1 ___y1 #define left ___left #define right ___right #define y0 ___y0 #define div ___div #define j0 ___j0 #define jn ___jn using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vl; const int N = 1e5 + 2; int n, K, a[N]; ll dp[2][N]; struct State { int val; ll mnDp, pmn; State(int v, ll m, ll pm) : val(v), mnDp(m), pmn(pm) {} }; deque<State> dq; int main() { #ifdef HynDuf freopen(task".in", "r", stdin); //freopen(task".out", "w", stdout); #else ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif cin >> n >> K; rep(i, 1, n) cin >> a[i]; int now = 0, lst = 1; rep(i, 1, n) dp[0][i] = 1e18; dp[0][0] = 0; rep(k, 1, K) { now ^= 1, lst ^= 1; dq.clear(); dq.pb(State(1e9, 1e18, 1e18)); rep(i, 0, n) dp[now][i] = 1e18; rep(i, 1, n) { ll mn = dp[lst][i - 1]; while (dq.back().val <= a[i]) mn = min(mn, dq.back().mnDp), dq.pop_back(); State tmp(a[i], mn, min(dq.back().pmn, mn + a[i])); dq.pb(tmp); dp[now][i] = dq.back().pmn; } //cerr << "Num seg: " << k << '\n'; //rep(i, 0, n) cerr << dp[now][i] << " \n"[i == n]; } cout << dp[now][n]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...