# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
700217 |
2023-02-18T23:05:45 Z |
kioto2 |
K blocks (IZhO14_blocks) |
C++14 |
|
227 ms |
88720 KB |
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define int long long
using namespace std;
const int N=1e5+10;
int a[N],n,k,f[N][110];
int pre[110];
signed main()
{
cin.tie(0)->ios_base::sync_with_stdio(0);
if(fopen("task.inp","r"))
{
freopen("task.inp","r",stdin);
freopen("task.out","w",stdout);
}
cin>>n>>k;
fori(i,1,n) cin>>a[i];
memset(f,50,sizeof(f));
f[0][1]=0;
fori(i,1,n) f[i][1]=max(f[i-1][1],a[i]);
fori(j,2,k)
{
stack<pair<int,int>> st;
fori(i,j,n)
{
int cur=f[i-1][j-1];
while(!st.empty() && a[st.top().second]<=a[i])
{
cur=min(cur,st.top().first);
st.pop();
}
f[i][j]=min(f[ (st.empty()?0:st.top().second) ][j],cur+a[i]);
st.push({ cur,i });
}
}
cout<<f[n][k];
}
Compilation message
blocks.cpp: In function 'int main()':
blocks.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | freopen("task.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen("task.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
86324 KB |
Output is correct |
2 |
Correct |
31 ms |
86372 KB |
Output is correct |
3 |
Correct |
36 ms |
86408 KB |
Output is correct |
4 |
Correct |
32 ms |
86348 KB |
Output is correct |
5 |
Correct |
33 ms |
86348 KB |
Output is correct |
6 |
Correct |
40 ms |
86328 KB |
Output is correct |
7 |
Correct |
41 ms |
86388 KB |
Output is correct |
8 |
Correct |
31 ms |
86340 KB |
Output is correct |
9 |
Correct |
32 ms |
86324 KB |
Output is correct |
10 |
Correct |
32 ms |
86352 KB |
Output is correct |
11 |
Correct |
32 ms |
86356 KB |
Output is correct |
12 |
Correct |
31 ms |
86356 KB |
Output is correct |
13 |
Correct |
33 ms |
86408 KB |
Output is correct |
14 |
Correct |
32 ms |
86356 KB |
Output is correct |
15 |
Correct |
32 ms |
86336 KB |
Output is correct |
16 |
Correct |
32 ms |
86348 KB |
Output is correct |
17 |
Correct |
38 ms |
86464 KB |
Output is correct |
18 |
Correct |
32 ms |
86328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
86416 KB |
Output is correct |
2 |
Correct |
32 ms |
86388 KB |
Output is correct |
3 |
Correct |
32 ms |
86348 KB |
Output is correct |
4 |
Correct |
33 ms |
86356 KB |
Output is correct |
5 |
Correct |
32 ms |
86380 KB |
Output is correct |
6 |
Correct |
32 ms |
86352 KB |
Output is correct |
7 |
Correct |
32 ms |
86352 KB |
Output is correct |
8 |
Correct |
33 ms |
86400 KB |
Output is correct |
9 |
Correct |
34 ms |
86344 KB |
Output is correct |
10 |
Correct |
35 ms |
86396 KB |
Output is correct |
11 |
Correct |
33 ms |
86380 KB |
Output is correct |
12 |
Correct |
33 ms |
86344 KB |
Output is correct |
13 |
Correct |
33 ms |
86352 KB |
Output is correct |
14 |
Correct |
33 ms |
86384 KB |
Output is correct |
15 |
Correct |
33 ms |
86348 KB |
Output is correct |
16 |
Correct |
33 ms |
86348 KB |
Output is correct |
17 |
Correct |
33 ms |
86428 KB |
Output is correct |
18 |
Correct |
35 ms |
86388 KB |
Output is correct |
19 |
Correct |
36 ms |
86416 KB |
Output is correct |
20 |
Correct |
33 ms |
86356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
86324 KB |
Output is correct |
2 |
Correct |
31 ms |
86372 KB |
Output is correct |
3 |
Correct |
36 ms |
86408 KB |
Output is correct |
4 |
Correct |
32 ms |
86348 KB |
Output is correct |
5 |
Correct |
33 ms |
86348 KB |
Output is correct |
6 |
Correct |
40 ms |
86328 KB |
Output is correct |
7 |
Correct |
41 ms |
86388 KB |
Output is correct |
8 |
Correct |
31 ms |
86340 KB |
Output is correct |
9 |
Correct |
32 ms |
86324 KB |
Output is correct |
10 |
Correct |
32 ms |
86352 KB |
Output is correct |
11 |
Correct |
32 ms |
86356 KB |
Output is correct |
12 |
Correct |
31 ms |
86356 KB |
Output is correct |
13 |
Correct |
33 ms |
86408 KB |
Output is correct |
14 |
Correct |
32 ms |
86356 KB |
Output is correct |
15 |
Correct |
32 ms |
86336 KB |
Output is correct |
16 |
Correct |
32 ms |
86348 KB |
Output is correct |
17 |
Correct |
38 ms |
86464 KB |
Output is correct |
18 |
Correct |
32 ms |
86328 KB |
Output is correct |
19 |
Correct |
32 ms |
86416 KB |
Output is correct |
20 |
Correct |
32 ms |
86388 KB |
Output is correct |
21 |
Correct |
32 ms |
86348 KB |
Output is correct |
22 |
Correct |
33 ms |
86356 KB |
Output is correct |
23 |
Correct |
32 ms |
86380 KB |
Output is correct |
24 |
Correct |
32 ms |
86352 KB |
Output is correct |
25 |
Correct |
32 ms |
86352 KB |
Output is correct |
26 |
Correct |
33 ms |
86400 KB |
Output is correct |
27 |
Correct |
34 ms |
86344 KB |
Output is correct |
28 |
Correct |
35 ms |
86396 KB |
Output is correct |
29 |
Correct |
33 ms |
86380 KB |
Output is correct |
30 |
Correct |
33 ms |
86344 KB |
Output is correct |
31 |
Correct |
33 ms |
86352 KB |
Output is correct |
32 |
Correct |
33 ms |
86384 KB |
Output is correct |
33 |
Correct |
33 ms |
86348 KB |
Output is correct |
34 |
Correct |
33 ms |
86348 KB |
Output is correct |
35 |
Correct |
33 ms |
86428 KB |
Output is correct |
36 |
Correct |
35 ms |
86388 KB |
Output is correct |
37 |
Correct |
36 ms |
86416 KB |
Output is correct |
38 |
Correct |
33 ms |
86356 KB |
Output is correct |
39 |
Correct |
32 ms |
86348 KB |
Output is correct |
40 |
Correct |
32 ms |
86396 KB |
Output is correct |
41 |
Correct |
33 ms |
86344 KB |
Output is correct |
42 |
Correct |
33 ms |
86384 KB |
Output is correct |
43 |
Correct |
33 ms |
86440 KB |
Output is correct |
44 |
Correct |
33 ms |
86356 KB |
Output is correct |
45 |
Correct |
33 ms |
86348 KB |
Output is correct |
46 |
Correct |
33 ms |
86420 KB |
Output is correct |
47 |
Correct |
35 ms |
86376 KB |
Output is correct |
48 |
Correct |
33 ms |
86324 KB |
Output is correct |
49 |
Correct |
33 ms |
86328 KB |
Output is correct |
50 |
Correct |
34 ms |
86436 KB |
Output is correct |
51 |
Correct |
40 ms |
86348 KB |
Output is correct |
52 |
Correct |
34 ms |
86300 KB |
Output is correct |
53 |
Correct |
41 ms |
86416 KB |
Output is correct |
54 |
Correct |
33 ms |
86348 KB |
Output is correct |
55 |
Correct |
37 ms |
86308 KB |
Output is correct |
56 |
Correct |
33 ms |
86348 KB |
Output is correct |
57 |
Correct |
33 ms |
86412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
86324 KB |
Output is correct |
2 |
Correct |
31 ms |
86372 KB |
Output is correct |
3 |
Correct |
36 ms |
86408 KB |
Output is correct |
4 |
Correct |
32 ms |
86348 KB |
Output is correct |
5 |
Correct |
33 ms |
86348 KB |
Output is correct |
6 |
Correct |
40 ms |
86328 KB |
Output is correct |
7 |
Correct |
41 ms |
86388 KB |
Output is correct |
8 |
Correct |
31 ms |
86340 KB |
Output is correct |
9 |
Correct |
32 ms |
86324 KB |
Output is correct |
10 |
Correct |
32 ms |
86352 KB |
Output is correct |
11 |
Correct |
32 ms |
86356 KB |
Output is correct |
12 |
Correct |
31 ms |
86356 KB |
Output is correct |
13 |
Correct |
33 ms |
86408 KB |
Output is correct |
14 |
Correct |
32 ms |
86356 KB |
Output is correct |
15 |
Correct |
32 ms |
86336 KB |
Output is correct |
16 |
Correct |
32 ms |
86348 KB |
Output is correct |
17 |
Correct |
38 ms |
86464 KB |
Output is correct |
18 |
Correct |
32 ms |
86328 KB |
Output is correct |
19 |
Correct |
32 ms |
86416 KB |
Output is correct |
20 |
Correct |
32 ms |
86388 KB |
Output is correct |
21 |
Correct |
32 ms |
86348 KB |
Output is correct |
22 |
Correct |
33 ms |
86356 KB |
Output is correct |
23 |
Correct |
32 ms |
86380 KB |
Output is correct |
24 |
Correct |
32 ms |
86352 KB |
Output is correct |
25 |
Correct |
32 ms |
86352 KB |
Output is correct |
26 |
Correct |
33 ms |
86400 KB |
Output is correct |
27 |
Correct |
34 ms |
86344 KB |
Output is correct |
28 |
Correct |
35 ms |
86396 KB |
Output is correct |
29 |
Correct |
33 ms |
86380 KB |
Output is correct |
30 |
Correct |
33 ms |
86344 KB |
Output is correct |
31 |
Correct |
33 ms |
86352 KB |
Output is correct |
32 |
Correct |
33 ms |
86384 KB |
Output is correct |
33 |
Correct |
33 ms |
86348 KB |
Output is correct |
34 |
Correct |
33 ms |
86348 KB |
Output is correct |
35 |
Correct |
33 ms |
86428 KB |
Output is correct |
36 |
Correct |
35 ms |
86388 KB |
Output is correct |
37 |
Correct |
36 ms |
86416 KB |
Output is correct |
38 |
Correct |
33 ms |
86356 KB |
Output is correct |
39 |
Correct |
32 ms |
86348 KB |
Output is correct |
40 |
Correct |
32 ms |
86396 KB |
Output is correct |
41 |
Correct |
33 ms |
86344 KB |
Output is correct |
42 |
Correct |
33 ms |
86384 KB |
Output is correct |
43 |
Correct |
33 ms |
86440 KB |
Output is correct |
44 |
Correct |
33 ms |
86356 KB |
Output is correct |
45 |
Correct |
33 ms |
86348 KB |
Output is correct |
46 |
Correct |
33 ms |
86420 KB |
Output is correct |
47 |
Correct |
35 ms |
86376 KB |
Output is correct |
48 |
Correct |
33 ms |
86324 KB |
Output is correct |
49 |
Correct |
33 ms |
86328 KB |
Output is correct |
50 |
Correct |
34 ms |
86436 KB |
Output is correct |
51 |
Correct |
40 ms |
86348 KB |
Output is correct |
52 |
Correct |
34 ms |
86300 KB |
Output is correct |
53 |
Correct |
41 ms |
86416 KB |
Output is correct |
54 |
Correct |
33 ms |
86348 KB |
Output is correct |
55 |
Correct |
37 ms |
86308 KB |
Output is correct |
56 |
Correct |
33 ms |
86348 KB |
Output is correct |
57 |
Correct |
33 ms |
86412 KB |
Output is correct |
58 |
Correct |
37 ms |
86568 KB |
Output is correct |
59 |
Correct |
38 ms |
86992 KB |
Output is correct |
60 |
Correct |
39 ms |
87076 KB |
Output is correct |
61 |
Correct |
73 ms |
87076 KB |
Output is correct |
62 |
Correct |
205 ms |
87960 KB |
Output is correct |
63 |
Correct |
46 ms |
87828 KB |
Output is correct |
64 |
Correct |
121 ms |
87852 KB |
Output is correct |
65 |
Correct |
33 ms |
86308 KB |
Output is correct |
66 |
Correct |
33 ms |
86340 KB |
Output is correct |
67 |
Correct |
37 ms |
86400 KB |
Output is correct |
68 |
Correct |
34 ms |
86460 KB |
Output is correct |
69 |
Correct |
35 ms |
86320 KB |
Output is correct |
70 |
Correct |
33 ms |
86412 KB |
Output is correct |
71 |
Correct |
47 ms |
86572 KB |
Output is correct |
72 |
Correct |
34 ms |
86556 KB |
Output is correct |
73 |
Correct |
39 ms |
86452 KB |
Output is correct |
74 |
Correct |
37 ms |
86984 KB |
Output is correct |
75 |
Correct |
42 ms |
87048 KB |
Output is correct |
76 |
Correct |
83 ms |
86988 KB |
Output is correct |
77 |
Correct |
212 ms |
87884 KB |
Output is correct |
78 |
Correct |
45 ms |
87772 KB |
Output is correct |
79 |
Correct |
136 ms |
87884 KB |
Output is correct |
80 |
Correct |
40 ms |
87864 KB |
Output is correct |
81 |
Correct |
56 ms |
87884 KB |
Output is correct |
82 |
Correct |
214 ms |
87800 KB |
Output is correct |
83 |
Correct |
33 ms |
86348 KB |
Output is correct |
84 |
Correct |
31 ms |
86340 KB |
Output is correct |
85 |
Correct |
45 ms |
86636 KB |
Output is correct |
86 |
Correct |
34 ms |
86540 KB |
Output is correct |
87 |
Correct |
36 ms |
86596 KB |
Output is correct |
88 |
Correct |
37 ms |
86988 KB |
Output is correct |
89 |
Correct |
41 ms |
87296 KB |
Output is correct |
90 |
Correct |
82 ms |
87336 KB |
Output is correct |
91 |
Correct |
227 ms |
88720 KB |
Output is correct |
92 |
Correct |
45 ms |
88468 KB |
Output is correct |
93 |
Correct |
143 ms |
88460 KB |
Output is correct |
94 |
Correct |
40 ms |
86488 KB |
Output is correct |
95 |
Correct |
45 ms |
86548 KB |
Output is correct |
96 |
Correct |
35 ms |
86348 KB |
Output is correct |
97 |
Correct |
33 ms |
86384 KB |
Output is correct |
98 |
Correct |
33 ms |
86348 KB |
Output is correct |
99 |
Correct |
33 ms |
86320 KB |
Output is correct |