# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647567 | x0r | K blocks (IZhO14_blocks) | C++17 | 1093 ms | 2388 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O2")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pll pair < ll, ll >
#define pii pair < int, int >
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const string NAME = "";
const string NAME2 = "TEST";
const ld ESP = 1e-9;
const ll INF = 1e9 + 7;
const ll LINF = 1E18;
const ll nmax = 2e5;
const ll MOD = 1e9 + 7;
const ll base = 2309;
void fre() {
string finp = NAME + ".inp";
string fout = NAME + ".out";
freopen(finp.c_str(), "r", stdin);
freopen(fout.c_str(), "w", stdout);
}
int n, k, a[100003], dp[103][100003], st[100003][23];
int get(int l, int r) {
int k = log2(r - l + 1);
return max(st[l][k], st[r - (1 << k) + 1][k]);
}
int main() {
fast;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
st[i][0] = a[i];
}
for (int j = 1; (1 << j) <= n; j++)
for (int i = 1; i + (1 << j) - 1 <= n; i++)
st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
for (int i = 2; i <= k; i++)
for (int j = 1; j <= n; j++) dp[i][j] = INF;
for (int i = 1; i <= n; i++) dp[1][i] = get(1, i);
for (int i = 2; i <= k; i++)
for (int j = i; j <= n; j++)
for (int k = j - 1; k >= i - 1; k--)
dp[i][j] = min(dp[i][j], dp[i - 1][k] + get(k + 1, j));
cout << dp[k][n];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |