# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1101528 |
2024-10-16T09:25:29 Z |
tuan19a |
K blocks (IZhO14_blocks) |
C++14 |
|
149 ms |
83456 KB |
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define el "\n"
#define FILE "test1"
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define bit(mask,i) ((mask>>i) & 1)
const int N=1e5+2;
const ll oo=1e18;
const int mod=1e9+7;
const int base=31;
const int dx[4]={0, 0, 1, -1};
const int dy[4]={1, -1, 0, 0};
using namespace std;
int n,k,a[N],dp[N][102],l[N],rmq[N][25];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
if (fopen(FILE".inp","r"))
{
freopen(FILE".inp","r",stdin);
freopen(FILE".out","w",stdout);
}
cin>>n>>k;
for (int i=1;i<=n;i++)
cin>>a[i];
memset(dp,0x3f,sizeof dp);
dp[0][1]=0;
for (int i=1;i<=n;i++) dp[i][1]=max(dp[i-1][1],a[i]);
for (int i=2;i<=k;i++)
{
stack <pii> s;
for (int j=i;j<=n;j++)
{
int minn=dp[j-1][i-1];
while (!s.empty() && a[j]>=a[s.top().se]) minn=min(minn,s.top().fi),s.pop();
int pos=0;
if (!s.empty()) pos=s.top().se;
dp[j][i]=min(dp[pos][i],minn+a[j]);
s.push({minn,j});
}
}
cout<<dp[n][k];
}
/** /\_/\
* (= ._.)
* / >AC \>AC
**/
Compilation message
blocks.cpp: In function 'int main()':
blocks.cpp:27:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen(FILE".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:28:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | freopen(FILE".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
82540 KB |
Output is correct |
2 |
Correct |
12 ms |
82512 KB |
Output is correct |
3 |
Correct |
11 ms |
82456 KB |
Output is correct |
4 |
Correct |
11 ms |
82520 KB |
Output is correct |
5 |
Correct |
11 ms |
82512 KB |
Output is correct |
6 |
Correct |
13 ms |
82512 KB |
Output is correct |
7 |
Correct |
11 ms |
82404 KB |
Output is correct |
8 |
Correct |
12 ms |
82512 KB |
Output is correct |
9 |
Correct |
12 ms |
82408 KB |
Output is correct |
10 |
Correct |
13 ms |
82512 KB |
Output is correct |
11 |
Correct |
12 ms |
82512 KB |
Output is correct |
12 |
Correct |
12 ms |
82512 KB |
Output is correct |
13 |
Correct |
13 ms |
82476 KB |
Output is correct |
14 |
Correct |
11 ms |
82508 KB |
Output is correct |
15 |
Correct |
11 ms |
82512 KB |
Output is correct |
16 |
Correct |
11 ms |
82680 KB |
Output is correct |
17 |
Correct |
13 ms |
82512 KB |
Output is correct |
18 |
Correct |
12 ms |
82512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
82512 KB |
Output is correct |
2 |
Correct |
11 ms |
82512 KB |
Output is correct |
3 |
Correct |
11 ms |
82512 KB |
Output is correct |
4 |
Correct |
13 ms |
82512 KB |
Output is correct |
5 |
Correct |
12 ms |
82680 KB |
Output is correct |
6 |
Correct |
15 ms |
82512 KB |
Output is correct |
7 |
Correct |
11 ms |
82512 KB |
Output is correct |
8 |
Correct |
11 ms |
82512 KB |
Output is correct |
9 |
Correct |
13 ms |
82512 KB |
Output is correct |
10 |
Correct |
12 ms |
82476 KB |
Output is correct |
11 |
Correct |
11 ms |
82512 KB |
Output is correct |
12 |
Correct |
11 ms |
82512 KB |
Output is correct |
13 |
Correct |
11 ms |
82512 KB |
Output is correct |
14 |
Correct |
12 ms |
82512 KB |
Output is correct |
15 |
Correct |
10 ms |
82516 KB |
Output is correct |
16 |
Correct |
10 ms |
82408 KB |
Output is correct |
17 |
Correct |
10 ms |
82512 KB |
Output is correct |
18 |
Correct |
10 ms |
82516 KB |
Output is correct |
19 |
Correct |
10 ms |
82512 KB |
Output is correct |
20 |
Correct |
10 ms |
82516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
82540 KB |
Output is correct |
2 |
Correct |
12 ms |
82512 KB |
Output is correct |
3 |
Correct |
11 ms |
82456 KB |
Output is correct |
4 |
Correct |
11 ms |
82520 KB |
Output is correct |
5 |
Correct |
11 ms |
82512 KB |
Output is correct |
6 |
Correct |
13 ms |
82512 KB |
Output is correct |
7 |
Correct |
11 ms |
82404 KB |
Output is correct |
8 |
Correct |
12 ms |
82512 KB |
Output is correct |
9 |
Correct |
12 ms |
82408 KB |
Output is correct |
10 |
Correct |
13 ms |
82512 KB |
Output is correct |
11 |
Correct |
12 ms |
82512 KB |
Output is correct |
12 |
Correct |
12 ms |
82512 KB |
Output is correct |
13 |
Correct |
13 ms |
82476 KB |
Output is correct |
14 |
Correct |
11 ms |
82508 KB |
Output is correct |
15 |
Correct |
11 ms |
82512 KB |
Output is correct |
16 |
Correct |
11 ms |
82680 KB |
Output is correct |
17 |
Correct |
13 ms |
82512 KB |
Output is correct |
18 |
Correct |
12 ms |
82512 KB |
Output is correct |
19 |
Correct |
11 ms |
82512 KB |
Output is correct |
20 |
Correct |
11 ms |
82512 KB |
Output is correct |
21 |
Correct |
11 ms |
82512 KB |
Output is correct |
22 |
Correct |
13 ms |
82512 KB |
Output is correct |
23 |
Correct |
12 ms |
82680 KB |
Output is correct |
24 |
Correct |
15 ms |
82512 KB |
Output is correct |
25 |
Correct |
11 ms |
82512 KB |
Output is correct |
26 |
Correct |
11 ms |
82512 KB |
Output is correct |
27 |
Correct |
13 ms |
82512 KB |
Output is correct |
28 |
Correct |
12 ms |
82476 KB |
Output is correct |
29 |
Correct |
11 ms |
82512 KB |
Output is correct |
30 |
Correct |
11 ms |
82512 KB |
Output is correct |
31 |
Correct |
11 ms |
82512 KB |
Output is correct |
32 |
Correct |
12 ms |
82512 KB |
Output is correct |
33 |
Correct |
10 ms |
82516 KB |
Output is correct |
34 |
Correct |
10 ms |
82408 KB |
Output is correct |
35 |
Correct |
10 ms |
82512 KB |
Output is correct |
36 |
Correct |
10 ms |
82516 KB |
Output is correct |
37 |
Correct |
10 ms |
82512 KB |
Output is correct |
38 |
Correct |
10 ms |
82516 KB |
Output is correct |
39 |
Correct |
11 ms |
82412 KB |
Output is correct |
40 |
Correct |
10 ms |
82452 KB |
Output is correct |
41 |
Correct |
11 ms |
82512 KB |
Output is correct |
42 |
Correct |
12 ms |
82512 KB |
Output is correct |
43 |
Correct |
11 ms |
82512 KB |
Output is correct |
44 |
Correct |
12 ms |
82512 KB |
Output is correct |
45 |
Correct |
10 ms |
82480 KB |
Output is correct |
46 |
Correct |
10 ms |
82512 KB |
Output is correct |
47 |
Correct |
10 ms |
82680 KB |
Output is correct |
48 |
Correct |
11 ms |
82512 KB |
Output is correct |
49 |
Correct |
13 ms |
82512 KB |
Output is correct |
50 |
Correct |
11 ms |
82528 KB |
Output is correct |
51 |
Correct |
12 ms |
82512 KB |
Output is correct |
52 |
Correct |
11 ms |
82512 KB |
Output is correct |
53 |
Correct |
13 ms |
82512 KB |
Output is correct |
54 |
Correct |
12 ms |
82532 KB |
Output is correct |
55 |
Correct |
12 ms |
82512 KB |
Output is correct |
56 |
Correct |
11 ms |
82512 KB |
Output is correct |
57 |
Correct |
13 ms |
82512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
82540 KB |
Output is correct |
2 |
Correct |
12 ms |
82512 KB |
Output is correct |
3 |
Correct |
11 ms |
82456 KB |
Output is correct |
4 |
Correct |
11 ms |
82520 KB |
Output is correct |
5 |
Correct |
11 ms |
82512 KB |
Output is correct |
6 |
Correct |
13 ms |
82512 KB |
Output is correct |
7 |
Correct |
11 ms |
82404 KB |
Output is correct |
8 |
Correct |
12 ms |
82512 KB |
Output is correct |
9 |
Correct |
12 ms |
82408 KB |
Output is correct |
10 |
Correct |
13 ms |
82512 KB |
Output is correct |
11 |
Correct |
12 ms |
82512 KB |
Output is correct |
12 |
Correct |
12 ms |
82512 KB |
Output is correct |
13 |
Correct |
13 ms |
82476 KB |
Output is correct |
14 |
Correct |
11 ms |
82508 KB |
Output is correct |
15 |
Correct |
11 ms |
82512 KB |
Output is correct |
16 |
Correct |
11 ms |
82680 KB |
Output is correct |
17 |
Correct |
13 ms |
82512 KB |
Output is correct |
18 |
Correct |
12 ms |
82512 KB |
Output is correct |
19 |
Correct |
11 ms |
82512 KB |
Output is correct |
20 |
Correct |
11 ms |
82512 KB |
Output is correct |
21 |
Correct |
11 ms |
82512 KB |
Output is correct |
22 |
Correct |
13 ms |
82512 KB |
Output is correct |
23 |
Correct |
12 ms |
82680 KB |
Output is correct |
24 |
Correct |
15 ms |
82512 KB |
Output is correct |
25 |
Correct |
11 ms |
82512 KB |
Output is correct |
26 |
Correct |
11 ms |
82512 KB |
Output is correct |
27 |
Correct |
13 ms |
82512 KB |
Output is correct |
28 |
Correct |
12 ms |
82476 KB |
Output is correct |
29 |
Correct |
11 ms |
82512 KB |
Output is correct |
30 |
Correct |
11 ms |
82512 KB |
Output is correct |
31 |
Correct |
11 ms |
82512 KB |
Output is correct |
32 |
Correct |
12 ms |
82512 KB |
Output is correct |
33 |
Correct |
10 ms |
82516 KB |
Output is correct |
34 |
Correct |
10 ms |
82408 KB |
Output is correct |
35 |
Correct |
10 ms |
82512 KB |
Output is correct |
36 |
Correct |
10 ms |
82516 KB |
Output is correct |
37 |
Correct |
10 ms |
82512 KB |
Output is correct |
38 |
Correct |
10 ms |
82516 KB |
Output is correct |
39 |
Correct |
11 ms |
82412 KB |
Output is correct |
40 |
Correct |
10 ms |
82452 KB |
Output is correct |
41 |
Correct |
11 ms |
82512 KB |
Output is correct |
42 |
Correct |
12 ms |
82512 KB |
Output is correct |
43 |
Correct |
11 ms |
82512 KB |
Output is correct |
44 |
Correct |
12 ms |
82512 KB |
Output is correct |
45 |
Correct |
10 ms |
82480 KB |
Output is correct |
46 |
Correct |
10 ms |
82512 KB |
Output is correct |
47 |
Correct |
10 ms |
82680 KB |
Output is correct |
48 |
Correct |
11 ms |
82512 KB |
Output is correct |
49 |
Correct |
13 ms |
82512 KB |
Output is correct |
50 |
Correct |
11 ms |
82528 KB |
Output is correct |
51 |
Correct |
12 ms |
82512 KB |
Output is correct |
52 |
Correct |
11 ms |
82512 KB |
Output is correct |
53 |
Correct |
13 ms |
82512 KB |
Output is correct |
54 |
Correct |
12 ms |
82532 KB |
Output is correct |
55 |
Correct |
12 ms |
82512 KB |
Output is correct |
56 |
Correct |
11 ms |
82512 KB |
Output is correct |
57 |
Correct |
13 ms |
82512 KB |
Output is correct |
58 |
Correct |
17 ms |
82512 KB |
Output is correct |
59 |
Correct |
18 ms |
82528 KB |
Output is correct |
60 |
Correct |
14 ms |
82512 KB |
Output is correct |
61 |
Correct |
55 ms |
82536 KB |
Output is correct |
62 |
Correct |
110 ms |
82688 KB |
Output is correct |
63 |
Correct |
20 ms |
82768 KB |
Output is correct |
64 |
Correct |
65 ms |
82768 KB |
Output is correct |
65 |
Correct |
13 ms |
82512 KB |
Output is correct |
66 |
Correct |
11 ms |
82512 KB |
Output is correct |
67 |
Correct |
13 ms |
82444 KB |
Output is correct |
68 |
Correct |
12 ms |
82512 KB |
Output is correct |
69 |
Correct |
13 ms |
82472 KB |
Output is correct |
70 |
Correct |
13 ms |
82532 KB |
Output is correct |
71 |
Correct |
27 ms |
82512 KB |
Output is correct |
72 |
Correct |
12 ms |
82440 KB |
Output is correct |
73 |
Correct |
14 ms |
82512 KB |
Output is correct |
74 |
Correct |
15 ms |
82388 KB |
Output is correct |
75 |
Correct |
16 ms |
82512 KB |
Output is correct |
76 |
Correct |
58 ms |
82536 KB |
Output is correct |
77 |
Correct |
141 ms |
82648 KB |
Output is correct |
78 |
Correct |
20 ms |
82796 KB |
Output is correct |
79 |
Correct |
73 ms |
82684 KB |
Output is correct |
80 |
Correct |
18 ms |
82792 KB |
Output is correct |
81 |
Correct |
27 ms |
82728 KB |
Output is correct |
82 |
Correct |
130 ms |
82784 KB |
Output is correct |
83 |
Correct |
12 ms |
82512 KB |
Output is correct |
84 |
Correct |
14 ms |
82512 KB |
Output is correct |
85 |
Correct |
23 ms |
82460 KB |
Output is correct |
86 |
Correct |
14 ms |
82512 KB |
Output is correct |
87 |
Correct |
17 ms |
82516 KB |
Output is correct |
88 |
Correct |
15 ms |
82512 KB |
Output is correct |
89 |
Correct |
18 ms |
82716 KB |
Output is correct |
90 |
Correct |
52 ms |
82812 KB |
Output is correct |
91 |
Correct |
149 ms |
83384 KB |
Output is correct |
92 |
Correct |
24 ms |
83344 KB |
Output is correct |
93 |
Correct |
81 ms |
83456 KB |
Output is correct |
94 |
Correct |
12 ms |
82512 KB |
Output is correct |
95 |
Correct |
23 ms |
82608 KB |
Output is correct |
96 |
Correct |
12 ms |
82512 KB |
Output is correct |
97 |
Correct |
12 ms |
82512 KB |
Output is correct |
98 |
Correct |
11 ms |
82432 KB |
Output is correct |
99 |
Correct |
12 ms |
82528 KB |
Output is correct |