# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
90670 |
2018-12-23T12:26:53 Z |
P1QG |
K blocks (IZhO14_blocks) |
C++11 |
|
291 ms |
42460 KB |
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int n, k, a[maxn], F[maxn][105];
int main()
{
//freopen("BLOCKS.inp","r",stdin);
//freopen("BLOCKS.out","w",stdout);
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] = 1e9+9;
}
F[0][1] = 0;
for(int i=1;i<=n;i++) F[i][1] = max(F[i-1][1], a[i]);
for(int i=2;i<=k;i++)
{
stack< pair<int,int> > P;
for(int j=i;j<=n;j++)
{
int cur = F[j-1][i-1];
while(P.size() && a[P.top().second] <= a[j])
{
cur = min(cur, P.top().first);
P.pop();
}
F[j][i] = min(cur + a[j], F[P.empty() ? 0 : P.top().second][i]);
P.push( make_pair(cur, j));
}
}
cout << F[n][k];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
524 KB |
Output is correct |
8 |
Correct |
2 ms |
524 KB |
Output is correct |
9 |
Correct |
2 ms |
524 KB |
Output is correct |
10 |
Correct |
2 ms |
524 KB |
Output is correct |
11 |
Correct |
2 ms |
524 KB |
Output is correct |
12 |
Correct |
2 ms |
524 KB |
Output is correct |
13 |
Correct |
2 ms |
524 KB |
Output is correct |
14 |
Correct |
2 ms |
524 KB |
Output is correct |
15 |
Correct |
2 ms |
524 KB |
Output is correct |
16 |
Correct |
2 ms |
564 KB |
Output is correct |
17 |
Correct |
2 ms |
580 KB |
Output is correct |
18 |
Correct |
2 ms |
708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
708 KB |
Output is correct |
2 |
Correct |
2 ms |
708 KB |
Output is correct |
3 |
Correct |
2 ms |
708 KB |
Output is correct |
4 |
Correct |
2 ms |
708 KB |
Output is correct |
5 |
Correct |
2 ms |
708 KB |
Output is correct |
6 |
Correct |
2 ms |
708 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
4732 KB |
Output is correct |
2 |
Correct |
29 ms |
19072 KB |
Output is correct |
3 |
Correct |
35 ms |
19072 KB |
Output is correct |
4 |
Correct |
89 ms |
19072 KB |
Output is correct |
5 |
Correct |
291 ms |
42236 KB |
Output is correct |
6 |
Correct |
72 ms |
42236 KB |
Output is correct |
7 |
Correct |
178 ms |
42236 KB |
Output is correct |
8 |
Correct |
2 ms |
42236 KB |
Output is correct |
9 |
Correct |
2 ms |
42236 KB |
Output is correct |
10 |
Correct |
2 ms |
42236 KB |
Output is correct |
11 |
Correct |
2 ms |
42236 KB |
Output is correct |
12 |
Correct |
2 ms |
42236 KB |
Output is correct |
13 |
Correct |
2 ms |
42236 KB |
Output is correct |
14 |
Correct |
25 ms |
42236 KB |
Output is correct |
15 |
Correct |
8 ms |
42236 KB |
Output is correct |
16 |
Correct |
12 ms |
42236 KB |
Output is correct |
17 |
Correct |
28 ms |
42236 KB |
Output is correct |
18 |
Correct |
32 ms |
42236 KB |
Output is correct |
19 |
Correct |
90 ms |
42236 KB |
Output is correct |
20 |
Correct |
258 ms |
42236 KB |
Output is correct |
21 |
Correct |
63 ms |
42236 KB |
Output is correct |
22 |
Correct |
148 ms |
42236 KB |
Output is correct |
23 |
Correct |
59 ms |
42236 KB |
Output is correct |
24 |
Correct |
76 ms |
42236 KB |
Output is correct |
25 |
Correct |
252 ms |
42236 KB |
Output is correct |
26 |
Correct |
2 ms |
42236 KB |
Output is correct |
27 |
Correct |
2 ms |
42236 KB |
Output is correct |
28 |
Correct |
22 ms |
42236 KB |
Output is correct |
29 |
Correct |
8 ms |
42236 KB |
Output is correct |
30 |
Correct |
11 ms |
42236 KB |
Output is correct |
31 |
Correct |
30 ms |
42236 KB |
Output is correct |
32 |
Correct |
35 ms |
42236 KB |
Output is correct |
33 |
Correct |
89 ms |
42236 KB |
Output is correct |
34 |
Correct |
275 ms |
42460 KB |
Output is correct |
35 |
Correct |
72 ms |
42460 KB |
Output is correct |
36 |
Correct |
177 ms |
42460 KB |
Output is correct |
37 |
Correct |
8 ms |
42460 KB |
Output is correct |
38 |
Correct |
21 ms |
42460 KB |
Output is correct |
39 |
Correct |
2 ms |
42460 KB |
Output is correct |
40 |
Correct |
2 ms |
42460 KB |
Output is correct |
41 |
Correct |
2 ms |
42460 KB |
Output is correct |
42 |
Correct |
2 ms |
42460 KB |
Output is correct |