# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
92769 |
2019-01-04T13:19:51 Z |
SamAnd |
K blocks (IZhO14_blocks) |
C++17 |
|
247 ms |
41212 KB |
#include <iostream>
#include <stack>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 100005, K = 102;
int n, k;
int a[N];
int dp[K][N];
int main()
{
//freopen("input2.txt", "r", stdin);
//freopen("blocks.in", "r", stdin);
//freopen("blocks.out", "w", stdout);
cin >> n >> k;
for (int i = 1; i <= n; ++i)
cin >> a[i];
int maxu = 0;
for (int j = 1; j <= n; ++j)
{
maxu = max(maxu, a[j]);
dp[1][j] = maxu;
}
for (int i = 2; i <= k; ++i)
{
stack<int> s, ss, minudp;
int minu;
for (int j = i; j <= n; ++j)
{
int cminudp = dp[i - 1][j - 1];
while (!s.empty() && a[j] >= s.top())
{
s.pop();
minu = s.top();
s.pop();
ss.pop();
cminudp = min(cminudp, minudp.top());
minudp.pop();
}
int x = a[j] + cminudp;
s.push(minu);
s.push(a[j]);
if (ss.empty())
minu = x;
else
minu = min(minu, x);
ss.push(j);
minudp.push(cminudp);
dp[i][j] = minu;
}
}
/*for (int j = 1; j <= n; ++j)
cout << dp[2][j] << endl;*/
cout << dp[k][n] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 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 |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
1 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
1 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
1 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
348 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 |
504 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 |
380 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 |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
252 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 |
436 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 |
248 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 |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
760 KB |
Output is correct |
16 |
Correct |
2 ms |
760 KB |
Output is correct |
17 |
Correct |
2 ms |
632 KB |
Output is correct |
18 |
Correct |
2 ms |
760 KB |
Output is correct |
19 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1528 KB |
Output is correct |
2 |
Correct |
15 ms |
1020 KB |
Output is correct |
3 |
Correct |
20 ms |
2040 KB |
Output is correct |
4 |
Correct |
68 ms |
14324 KB |
Output is correct |
5 |
Correct |
188 ms |
40508 KB |
Output is correct |
6 |
Correct |
36 ms |
2816 KB |
Output is correct |
7 |
Correct |
103 ms |
19072 KB |
Output is correct |
8 |
Correct |
2 ms |
496 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
2 ms |
632 KB |
Output is correct |
11 |
Correct |
2 ms |
636 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
27 ms |
4856 KB |
Output is correct |
15 |
Correct |
5 ms |
544 KB |
Output is correct |
16 |
Correct |
10 ms |
1528 KB |
Output is correct |
17 |
Correct |
16 ms |
1016 KB |
Output is correct |
18 |
Correct |
21 ms |
2040 KB |
Output is correct |
19 |
Correct |
93 ms |
14360 KB |
Output is correct |
20 |
Correct |
246 ms |
40712 KB |
Output is correct |
21 |
Correct |
37 ms |
2552 KB |
Output is correct |
22 |
Correct |
131 ms |
19100 KB |
Output is correct |
23 |
Correct |
33 ms |
1784 KB |
Output is correct |
24 |
Correct |
51 ms |
5368 KB |
Output is correct |
25 |
Correct |
247 ms |
40552 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
508 KB |
Output is correct |
28 |
Correct |
23 ms |
4856 KB |
Output is correct |
29 |
Correct |
5 ms |
632 KB |
Output is correct |
30 |
Correct |
9 ms |
1656 KB |
Output is correct |
31 |
Correct |
15 ms |
1016 KB |
Output is correct |
32 |
Correct |
21 ms |
2384 KB |
Output is correct |
33 |
Correct |
78 ms |
14632 KB |
Output is correct |
34 |
Correct |
225 ms |
41212 KB |
Output is correct |
35 |
Correct |
37 ms |
3116 KB |
Output is correct |
36 |
Correct |
124 ms |
19636 KB |
Output is correct |
37 |
Correct |
5 ms |
504 KB |
Output is correct |
38 |
Correct |
21 ms |
4856 KB |
Output is correct |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |