# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
171740 |
2019-12-30T08:55:08 Z |
VEGAnn |
K blocks (IZhO14_blocks) |
C++14 |
|
27 ms |
4728 KB |
#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
const int N = 100100;
const int K = 110;
int f[N][K], a[N], n, k;
bool bad = 0;
void calc(int j, int l, int r, int optl, int optr){
if (l > r) return;
int md = (l + r) >> 1;
int mx = 0, mn = oo, ps = -1;
for (int i = min(md, optr); i >= optl; i--){
mx = max(mx, a[i]);
if (f[i - 1][j - 1] < oo &&
mn >= f[i - 1][j - 1] + mx){
mn = f[i - 1][j - 1] + mx;
ps = i;
}
}
if (mn == oo) bad = 1;
f[md][j] = mn;
calc(j, l, md - 1, optl, ps);
calc(j, md + 1, r, ps, optr);
}
int main(){
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= k; j++)
f[i][j] = oo;
f[0][0] = 0;
for (int j = 1; j <= k; j++)
calc(j, 1, n, 1, n);
if (bad) return -1;
cout << f[n][k];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Runtime error |
2 ms |
380 KB |
Execution failed because the return code was nonzero |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Runtime error |
2 ms |
256 KB |
Execution failed because the return code was nonzero |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
376 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
27 ms |
4728 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |