제출 #1254544

#제출 시각아이디문제언어결과실행 시간메모리
1254544rhm_ganK blocks (IZhO14_blocks)C++20
0 / 100
0 ms468 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define dbg(...) 42 #endif vector<int> st, a; void build(int id, int tl, int tr) { if (tl == tr) { st[id] = a[tl]; return; } int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1; build(x, tl, tm); build(y, tm + 1, tr); st[id] = max(st[x], st[y]); } int query(int id, int tl, int tr, int l, int r) { if (r < tl || tr < l) return 0; if (l <= tl && tr <= r) return st[id]; int x = (id << 1) + 1, y = x + 1, tm = (tl + tr) >> 1; return max(query(x, tl, tm, l, r), query(y, tm + 1, tr, l, r)); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; a.resize(n + 1, 0); st.assign(4 * n + 10, 0); for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); build(0, 0, n); vector<vector<int64_t>> dp(n + 1, vector<int64_t>(k + 1, 1e18)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= min(i, k); j++) { for (int r = 0; r <= i; r++) { dp[i][j] = min(dp[i][j], dp[r][j - 1] + query(0, 0, n, r, i)); } } } cout << dp[n][k] << '\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...