# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
171751 |
2019-12-30T09:51:32 Z |
VEGAnn |
K blocks (IZhO14_blocks) |
C++14 |
|
1000 ms |
52600 KB |
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define MP make_pair
#define ft first
#define sd second
#define pii pair<int, int>
using namespace std;
const int oo = 1e9;
const int N = 100100;
const int K = 110;
const int PW = 20;
stack<pii> st;
int f[N][K], a[N], n, k, sp[N][PW], prec[N];
int get_min(int l, int r){
assert(l <= r);
int len = r - l + 1;
return min(sp[l + (1 << prec[len]) - 1][prec[len]], sp[r][prec[len]]);
}
int main(){
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
a[0] = oo;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= k; j++)
f[i][j] = oo;
f[0][0] = 0;
prec[0] = -1;
for (int i = 1; i <= n; i++)
prec[i] = prec[i >> 1] + 1;
for (int j = 1; j <= k; j++) {
while (sz(st)) st.pop();
st.push(MP(0, oo));
for (int i = 1; i <= n; i++){
sp[i][0] = f[i - 1][j - 1];
for (int po = 1; po < PW; po++){
if (i - (1 << po) + 1 < 1) break;
sp[i][po] = min(sp[i][po - 1], sp[i - (1 << (po - 1))][po - 1]);
}
while (a[st.top().ft] <= a[i])
st.pop();
pii cr = st.top();
st.push(MP(i, min(cr.sd, get_min(cr.ft + 1, i) + a[i])));
f[i][j] = st.top().sd;
}
}
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 |
380 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 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
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 |
380 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 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
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 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
5496 KB |
Output is correct |
2 |
Correct |
48 ms |
23332 KB |
Output is correct |
3 |
Correct |
68 ms |
23288 KB |
Output is correct |
4 |
Correct |
318 ms |
23416 KB |
Output is correct |
5 |
Execution timed out |
1094 ms |
52600 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |