# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
171743 |
2019-12-30T09:03:44 Z |
VEGAnn |
K blocks (IZhO14_blocks) |
C++14 |
|
45 ms |
5496 KB |
#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
const int N = 100100;
const int K = 110;
const int PW = 20;
int f[N][K], a[N], n, k, sp[N][PW], prec[N];
bool bad = 0;
int get_max(int l, int r){
if (l > r) swap(l, r);
int len = r - l + 1;
return max(sp[l][prec[len]], sp[r - (1 << prec[len]) + 1][prec[len]]);
}
void calc(int j, int l, int r, int optl, int optr){
if (l > r) return;
int md = (l + r) >> 1;
int mn = oo, ps = -1;
for (int i = optl; i <= optr; i++){
int mx = get_max(i, md);
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];
prec[0] = -1;
for (int i = 1; i <= n; i++)
prec[i] = prec[i >> 1] + 1;
for (int i = 1; i <= n; i++)
sp[i][0] = a[i];
for (int po = 1; po < PW; po++)
for (int i = 1; i <= n; i++){
if (i + (1 << po) - 1 > n) continue;
sp[i][po] = max(sp[i][po - 1], sp[i + (1 << (po - 1))][po - 1]);
}
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 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
372 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
5496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |