# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
203804 |
2020-02-22T08:06:10 Z |
zufius |
K blocks (IZhO14_blocks) |
C++14 |
|
1000 ms |
8444 KB |
#include <iostream>
#include <stdio.h>
#include <deque>
using namespace std;
typedef long long ll;
const int N = 1e5 + 11;
const ll oo = 1e18;
int n,k,lastGreater[N];
ll f[N][101],a[N],minf[N];
deque <int> Q;
void init(){
ll cur = -1;
for(int i = 1; i <= n; ++i){
cur = max(cur,a[i]);
f[i][1] = cur;
}
for(int i = 1; i <= n; ++i){
lastGreater[i] = 0;
while(Q.size() && a[Q.back()] <= a[i]) Q.pop_back();
if(Q.size()) lastGreater[i] = Q.back();
Q.push_back(i);
}
//for(int i = 1; i <= n; ++i) cout << i << " ~> " << lastGreater[i] << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
cin >> n >> k;
for(int i = 1; i <= n; ++i) cin >> a[i];
for(int i = 0; i <= n; ++i)
for(int j = 1; j <= k; ++j) f[i][j] = oo;
init();
for(int j = 2; j <= k; ++j){
/*minf[0] = oo;
Q.clear();
for(int i = 1; i <= n; ++i){
minf[i] = oo;
while(Q.size() && Q.front() < lastGreater[i]) Q.pop_front();
while(Q.size() && f[Q.back()][j - 1] >= f[i - 1][j - 1]){
Q.pop_back();
}
Q.push_back(i - 1);
minf[i] = f[Q.front()][j - 1] + a[i];
}
for(int i = 1; i <= n; ++i){
f[i][j] = minf[i] = min(minf[i],minf[lastGreater[i]]);
}*/
for(int i = 1; i <= n; ++i){
ll cc = 0;
for(int v = i; v > 0; --v){
cc = max(cc,a[v]);
f[i][j] = min(f[i][j],f[v - 1][j - 1] + cc);
}
}
}
cout << f[n][k];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
380 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
380 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
372 KB |
Output is correct |
18 |
Correct |
5 ms |
504 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
380 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
480 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
8444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |