# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
874012 |
2023-11-16T07:43:05 Z |
8pete8 |
K blocks (IZhO14_blocks) |
C++14 |
|
402 ms |
6232 KB |
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include <iomanip>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
#define double long double
const int mxn=1e5,inf=1e18;
int seg[2*mxn+10],n,dp[mxn+10],l[mxn+10],r[mxn+10],v[mxn+10],k;
int qry(int l,int r){
int ans=inf;
for(l+=n,r+=n;l<=r;l>>=1,r>>=1){
if(l&1)ans=min(ans,seg[l++]);
if(!(r&1))ans=min(ans,seg[r--]);
}
return ans;
}
void build(){for(int i=n-1;i>=0;i--)seg[i]=min(seg[i<<1],seg[(i<<1)^1]);}
int32_t main(){
fastio
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>v[i];
stack<int>st;
n++;
for(int i=1;i<n;i++){
while(!st.empty()&&v[st.top()]<=v[i])st.pop();
if(!st.empty())l[i]=st.top();
else l[i]=0;
st.push(i);
}
while(!st.empty())st.pop();
for(int i=n-1;i>=1;i--){
while(!st.empty()&&v[st.top()]<=v[i])st.pop();
if(!st.empty())r[i]=st.top();
else r[i]=n;
st.push(i);
}
for(int i=0;i<2*n;i++)seg[i]=inf;
seg[n]=0;
build();
stack<int>st2;
for(int j=0;j<k;j++){
for(int i=0;i<n;i++)dp[i]=inf;
for(int i=j;i<n;i++){
int g=qry(l[i],i-1)+v[i];
while(!st2.empty()&&(v[st2.top()]<=v[i]))st2.pop();
if(!st2.empty())g=min(g,dp[st2.top()]);
dp[i]=g;
st2.push(i);
}
for(int i=0;i<n;i++)seg[i+n]=dp[i];
build();
while(!st2.empty())st2.pop();
}
cout<<dp[n-1];
}
Compilation message
blocks.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
32 | #pragma GCC optimize ("03,unroll-lopps")
| ^
blocks.cpp:37:20: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
37 | int qry(int l,int r){
| ^
blocks.cpp:45:12: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
45 | void build(){for(int i=n-1;i>=0;i--)seg[i]=min(seg[i<<1],seg[(i<<1)^1]);}
| ^
blocks.cpp:46:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
46 | int32_t main(){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4696 KB |
Output is correct |
16 |
Correct |
1 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
4560 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4556 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4560 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4560 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4556 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4696 KB |
Output is correct |
16 |
Correct |
1 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
4560 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4556 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4440 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4560 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4440 KB |
Output is correct |
31 |
Correct |
1 ms |
4440 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4560 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4556 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4440 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
2 ms |
4600 KB |
Output is correct |
42 |
Correct |
1 ms |
4444 KB |
Output is correct |
43 |
Correct |
1 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4444 KB |
Output is correct |
45 |
Correct |
1 ms |
4444 KB |
Output is correct |
46 |
Correct |
1 ms |
4444 KB |
Output is correct |
47 |
Correct |
1 ms |
4444 KB |
Output is correct |
48 |
Correct |
1 ms |
4444 KB |
Output is correct |
49 |
Correct |
1 ms |
4444 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
1 ms |
4444 KB |
Output is correct |
52 |
Correct |
1 ms |
4444 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
54 |
Correct |
1 ms |
4560 KB |
Output is correct |
55 |
Correct |
1 ms |
4696 KB |
Output is correct |
56 |
Correct |
1 ms |
4444 KB |
Output is correct |
57 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4696 KB |
Output is correct |
16 |
Correct |
1 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
4560 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4556 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4440 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4560 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4440 KB |
Output is correct |
31 |
Correct |
1 ms |
4440 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4560 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4556 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4440 KB |
Output is correct |
40 |
Correct |
1 ms |
4444 KB |
Output is correct |
41 |
Correct |
2 ms |
4600 KB |
Output is correct |
42 |
Correct |
1 ms |
4444 KB |
Output is correct |
43 |
Correct |
1 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4444 KB |
Output is correct |
45 |
Correct |
1 ms |
4444 KB |
Output is correct |
46 |
Correct |
1 ms |
4444 KB |
Output is correct |
47 |
Correct |
1 ms |
4444 KB |
Output is correct |
48 |
Correct |
1 ms |
4444 KB |
Output is correct |
49 |
Correct |
1 ms |
4444 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
1 ms |
4444 KB |
Output is correct |
52 |
Correct |
1 ms |
4444 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
54 |
Correct |
1 ms |
4560 KB |
Output is correct |
55 |
Correct |
1 ms |
4696 KB |
Output is correct |
56 |
Correct |
1 ms |
4444 KB |
Output is correct |
57 |
Correct |
1 ms |
4444 KB |
Output is correct |
58 |
Correct |
11 ms |
4700 KB |
Output is correct |
59 |
Correct |
6 ms |
5048 KB |
Output is correct |
60 |
Correct |
17 ms |
4948 KB |
Output is correct |
61 |
Correct |
133 ms |
4956 KB |
Output is correct |
62 |
Correct |
402 ms |
5980 KB |
Output is correct |
63 |
Correct |
22 ms |
5980 KB |
Output is correct |
64 |
Correct |
180 ms |
6112 KB |
Output is correct |
65 |
Correct |
1 ms |
4444 KB |
Output is correct |
66 |
Correct |
1 ms |
4440 KB |
Output is correct |
67 |
Correct |
1 ms |
4444 KB |
Output is correct |
68 |
Correct |
1 ms |
4444 KB |
Output is correct |
69 |
Correct |
1 ms |
4564 KB |
Output is correct |
70 |
Correct |
1 ms |
4444 KB |
Output is correct |
71 |
Correct |
23 ms |
4700 KB |
Output is correct |
72 |
Correct |
2 ms |
4696 KB |
Output is correct |
73 |
Correct |
6 ms |
4700 KB |
Output is correct |
74 |
Correct |
6 ms |
4952 KB |
Output is correct |
75 |
Correct |
11 ms |
4956 KB |
Output is correct |
76 |
Correct |
71 ms |
5020 KB |
Output is correct |
77 |
Correct |
207 ms |
5804 KB |
Output is correct |
78 |
Correct |
16 ms |
5724 KB |
Output is correct |
79 |
Correct |
98 ms |
5720 KB |
Output is correct |
80 |
Correct |
11 ms |
5720 KB |
Output is correct |
81 |
Correct |
29 ms |
5680 KB |
Output is correct |
82 |
Correct |
214 ms |
5816 KB |
Output is correct |
83 |
Correct |
1 ms |
4440 KB |
Output is correct |
84 |
Correct |
1 ms |
4440 KB |
Output is correct |
85 |
Correct |
15 ms |
4700 KB |
Output is correct |
86 |
Correct |
2 ms |
4656 KB |
Output is correct |
87 |
Correct |
5 ms |
4700 KB |
Output is correct |
88 |
Correct |
5 ms |
4956 KB |
Output is correct |
89 |
Correct |
8 ms |
4956 KB |
Output is correct |
90 |
Correct |
51 ms |
4956 KB |
Output is correct |
91 |
Correct |
142 ms |
5980 KB |
Output is correct |
92 |
Correct |
14 ms |
5976 KB |
Output is correct |
93 |
Correct |
69 ms |
6232 KB |
Output is correct |
94 |
Correct |
3 ms |
4696 KB |
Output is correct |
95 |
Correct |
37 ms |
4696 KB |
Output is correct |
96 |
Correct |
1 ms |
4444 KB |
Output is correct |
97 |
Correct |
1 ms |
4444 KB |
Output is correct |
98 |
Correct |
1 ms |
4444 KB |
Output is correct |
99 |
Correct |
1 ms |
4440 KB |
Output is correct |