# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
444689 |
2021-07-14T20:20:23 Z |
NaimSS |
K blocks (IZhO14_blocks) |
C++14 |
|
296 ms |
89472 KB |
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
//inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll b,ll e,ll m){
b%=m;
ll ans = 1;
for (; e; b = b * b % m, e /= 2)
if (e & 1) ans = ans * b % m;
return ans;
}
// debug:
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){
cerr << ' ' << H;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr<<"(" << #__VA_ARGS__<<"):" , dbg_out(__VA_ARGS__) , cerr << endl
#else
#define dbg(...)
#endif
//
const int N = 100100;
ll A[N],B[N];
ll dp[100100][110];
int32_t main(){
fastio;
int n,k;
cin >> n >> k;
rep(i,0,100100)rep(j,0,110)dp[i][j] = 1e18;
ll mx=0;
rep(i,1,n+1){
cin >> A[i];
B[i] = A[i];
mx=max(mx,A[i]);
dp[i][1] = mx;
}
sort(B+1,B+1+n,greater<ll>());
rep(i,2,k+1){
stack<pll> st;
rep(j,1,n+1){
ll val = dp[j-1][i-1];
while(!st.empty() && st.top().ff < A[j]){
val=min(val,st.top().ss);
st.pop();
}
if(st.empty() || st.top().ff + st.top().ss > A[j] + val){
st.push(pll(A[j],val));
}
if(j>=i)
dp[j][i] = st.top().ff + st.top().ss;
}
}
cout << dp[n][k] << endl;
// math -> gcd it all
// Did u check N=1? Did you switch N,M?
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
86456 KB |
Output is correct |
2 |
Correct |
43 ms |
86468 KB |
Output is correct |
3 |
Correct |
43 ms |
86392 KB |
Output is correct |
4 |
Correct |
44 ms |
86444 KB |
Output is correct |
5 |
Correct |
43 ms |
86384 KB |
Output is correct |
6 |
Correct |
43 ms |
86468 KB |
Output is correct |
7 |
Correct |
43 ms |
86468 KB |
Output is correct |
8 |
Correct |
46 ms |
86400 KB |
Output is correct |
9 |
Correct |
44 ms |
86452 KB |
Output is correct |
10 |
Correct |
43 ms |
86452 KB |
Output is correct |
11 |
Correct |
43 ms |
86476 KB |
Output is correct |
12 |
Correct |
44 ms |
86444 KB |
Output is correct |
13 |
Correct |
45 ms |
86488 KB |
Output is correct |
14 |
Correct |
44 ms |
86460 KB |
Output is correct |
15 |
Correct |
44 ms |
86392 KB |
Output is correct |
16 |
Correct |
43 ms |
86388 KB |
Output is correct |
17 |
Correct |
44 ms |
86468 KB |
Output is correct |
18 |
Correct |
44 ms |
86468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
86400 KB |
Output is correct |
2 |
Correct |
45 ms |
86532 KB |
Output is correct |
3 |
Correct |
44 ms |
86504 KB |
Output is correct |
4 |
Correct |
43 ms |
86460 KB |
Output is correct |
5 |
Correct |
44 ms |
86472 KB |
Output is correct |
6 |
Correct |
44 ms |
86416 KB |
Output is correct |
7 |
Correct |
43 ms |
86512 KB |
Output is correct |
8 |
Correct |
43 ms |
86468 KB |
Output is correct |
9 |
Correct |
43 ms |
86540 KB |
Output is correct |
10 |
Correct |
45 ms |
86512 KB |
Output is correct |
11 |
Correct |
43 ms |
86420 KB |
Output is correct |
12 |
Correct |
44 ms |
86468 KB |
Output is correct |
13 |
Correct |
44 ms |
86420 KB |
Output is correct |
14 |
Correct |
44 ms |
86384 KB |
Output is correct |
15 |
Correct |
45 ms |
86480 KB |
Output is correct |
16 |
Correct |
44 ms |
86468 KB |
Output is correct |
17 |
Correct |
43 ms |
86428 KB |
Output is correct |
18 |
Correct |
50 ms |
86436 KB |
Output is correct |
19 |
Correct |
45 ms |
86476 KB |
Output is correct |
20 |
Correct |
45 ms |
86372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
86456 KB |
Output is correct |
2 |
Correct |
43 ms |
86468 KB |
Output is correct |
3 |
Correct |
43 ms |
86392 KB |
Output is correct |
4 |
Correct |
44 ms |
86444 KB |
Output is correct |
5 |
Correct |
43 ms |
86384 KB |
Output is correct |
6 |
Correct |
43 ms |
86468 KB |
Output is correct |
7 |
Correct |
43 ms |
86468 KB |
Output is correct |
8 |
Correct |
46 ms |
86400 KB |
Output is correct |
9 |
Correct |
44 ms |
86452 KB |
Output is correct |
10 |
Correct |
43 ms |
86452 KB |
Output is correct |
11 |
Correct |
43 ms |
86476 KB |
Output is correct |
12 |
Correct |
44 ms |
86444 KB |
Output is correct |
13 |
Correct |
45 ms |
86488 KB |
Output is correct |
14 |
Correct |
44 ms |
86460 KB |
Output is correct |
15 |
Correct |
44 ms |
86392 KB |
Output is correct |
16 |
Correct |
43 ms |
86388 KB |
Output is correct |
17 |
Correct |
44 ms |
86468 KB |
Output is correct |
18 |
Correct |
44 ms |
86468 KB |
Output is correct |
19 |
Correct |
44 ms |
86400 KB |
Output is correct |
20 |
Correct |
45 ms |
86532 KB |
Output is correct |
21 |
Correct |
44 ms |
86504 KB |
Output is correct |
22 |
Correct |
43 ms |
86460 KB |
Output is correct |
23 |
Correct |
44 ms |
86472 KB |
Output is correct |
24 |
Correct |
44 ms |
86416 KB |
Output is correct |
25 |
Correct |
43 ms |
86512 KB |
Output is correct |
26 |
Correct |
43 ms |
86468 KB |
Output is correct |
27 |
Correct |
43 ms |
86540 KB |
Output is correct |
28 |
Correct |
45 ms |
86512 KB |
Output is correct |
29 |
Correct |
43 ms |
86420 KB |
Output is correct |
30 |
Correct |
44 ms |
86468 KB |
Output is correct |
31 |
Correct |
44 ms |
86420 KB |
Output is correct |
32 |
Correct |
44 ms |
86384 KB |
Output is correct |
33 |
Correct |
45 ms |
86480 KB |
Output is correct |
34 |
Correct |
44 ms |
86468 KB |
Output is correct |
35 |
Correct |
43 ms |
86428 KB |
Output is correct |
36 |
Correct |
50 ms |
86436 KB |
Output is correct |
37 |
Correct |
45 ms |
86476 KB |
Output is correct |
38 |
Correct |
45 ms |
86372 KB |
Output is correct |
39 |
Correct |
44 ms |
86444 KB |
Output is correct |
40 |
Correct |
43 ms |
86488 KB |
Output is correct |
41 |
Correct |
44 ms |
86468 KB |
Output is correct |
42 |
Correct |
43 ms |
86464 KB |
Output is correct |
43 |
Correct |
44 ms |
86452 KB |
Output is correct |
44 |
Correct |
43 ms |
86488 KB |
Output is correct |
45 |
Correct |
44 ms |
86400 KB |
Output is correct |
46 |
Correct |
42 ms |
86432 KB |
Output is correct |
47 |
Correct |
44 ms |
86472 KB |
Output is correct |
48 |
Correct |
43 ms |
86392 KB |
Output is correct |
49 |
Correct |
43 ms |
86464 KB |
Output is correct |
50 |
Correct |
42 ms |
86412 KB |
Output is correct |
51 |
Correct |
43 ms |
86440 KB |
Output is correct |
52 |
Correct |
44 ms |
86468 KB |
Output is correct |
53 |
Correct |
43 ms |
86540 KB |
Output is correct |
54 |
Correct |
44 ms |
86460 KB |
Output is correct |
55 |
Correct |
43 ms |
86484 KB |
Output is correct |
56 |
Correct |
44 ms |
86432 KB |
Output is correct |
57 |
Correct |
43 ms |
86412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
86456 KB |
Output is correct |
2 |
Correct |
43 ms |
86468 KB |
Output is correct |
3 |
Correct |
43 ms |
86392 KB |
Output is correct |
4 |
Correct |
44 ms |
86444 KB |
Output is correct |
5 |
Correct |
43 ms |
86384 KB |
Output is correct |
6 |
Correct |
43 ms |
86468 KB |
Output is correct |
7 |
Correct |
43 ms |
86468 KB |
Output is correct |
8 |
Correct |
46 ms |
86400 KB |
Output is correct |
9 |
Correct |
44 ms |
86452 KB |
Output is correct |
10 |
Correct |
43 ms |
86452 KB |
Output is correct |
11 |
Correct |
43 ms |
86476 KB |
Output is correct |
12 |
Correct |
44 ms |
86444 KB |
Output is correct |
13 |
Correct |
45 ms |
86488 KB |
Output is correct |
14 |
Correct |
44 ms |
86460 KB |
Output is correct |
15 |
Correct |
44 ms |
86392 KB |
Output is correct |
16 |
Correct |
43 ms |
86388 KB |
Output is correct |
17 |
Correct |
44 ms |
86468 KB |
Output is correct |
18 |
Correct |
44 ms |
86468 KB |
Output is correct |
19 |
Correct |
44 ms |
86400 KB |
Output is correct |
20 |
Correct |
45 ms |
86532 KB |
Output is correct |
21 |
Correct |
44 ms |
86504 KB |
Output is correct |
22 |
Correct |
43 ms |
86460 KB |
Output is correct |
23 |
Correct |
44 ms |
86472 KB |
Output is correct |
24 |
Correct |
44 ms |
86416 KB |
Output is correct |
25 |
Correct |
43 ms |
86512 KB |
Output is correct |
26 |
Correct |
43 ms |
86468 KB |
Output is correct |
27 |
Correct |
43 ms |
86540 KB |
Output is correct |
28 |
Correct |
45 ms |
86512 KB |
Output is correct |
29 |
Correct |
43 ms |
86420 KB |
Output is correct |
30 |
Correct |
44 ms |
86468 KB |
Output is correct |
31 |
Correct |
44 ms |
86420 KB |
Output is correct |
32 |
Correct |
44 ms |
86384 KB |
Output is correct |
33 |
Correct |
45 ms |
86480 KB |
Output is correct |
34 |
Correct |
44 ms |
86468 KB |
Output is correct |
35 |
Correct |
43 ms |
86428 KB |
Output is correct |
36 |
Correct |
50 ms |
86436 KB |
Output is correct |
37 |
Correct |
45 ms |
86476 KB |
Output is correct |
38 |
Correct |
45 ms |
86372 KB |
Output is correct |
39 |
Correct |
44 ms |
86444 KB |
Output is correct |
40 |
Correct |
43 ms |
86488 KB |
Output is correct |
41 |
Correct |
44 ms |
86468 KB |
Output is correct |
42 |
Correct |
43 ms |
86464 KB |
Output is correct |
43 |
Correct |
44 ms |
86452 KB |
Output is correct |
44 |
Correct |
43 ms |
86488 KB |
Output is correct |
45 |
Correct |
44 ms |
86400 KB |
Output is correct |
46 |
Correct |
42 ms |
86432 KB |
Output is correct |
47 |
Correct |
44 ms |
86472 KB |
Output is correct |
48 |
Correct |
43 ms |
86392 KB |
Output is correct |
49 |
Correct |
43 ms |
86464 KB |
Output is correct |
50 |
Correct |
42 ms |
86412 KB |
Output is correct |
51 |
Correct |
43 ms |
86440 KB |
Output is correct |
52 |
Correct |
44 ms |
86468 KB |
Output is correct |
53 |
Correct |
43 ms |
86540 KB |
Output is correct |
54 |
Correct |
44 ms |
86460 KB |
Output is correct |
55 |
Correct |
43 ms |
86484 KB |
Output is correct |
56 |
Correct |
44 ms |
86432 KB |
Output is correct |
57 |
Correct |
43 ms |
86412 KB |
Output is correct |
58 |
Correct |
47 ms |
86604 KB |
Output is correct |
59 |
Correct |
50 ms |
87492 KB |
Output is correct |
60 |
Correct |
53 ms |
87564 KB |
Output is correct |
61 |
Correct |
87 ms |
87496 KB |
Output is correct |
62 |
Correct |
233 ms |
88672 KB |
Output is correct |
63 |
Correct |
61 ms |
88644 KB |
Output is correct |
64 |
Correct |
134 ms |
88816 KB |
Output is correct |
65 |
Correct |
46 ms |
86420 KB |
Output is correct |
66 |
Correct |
44 ms |
86468 KB |
Output is correct |
67 |
Correct |
44 ms |
86484 KB |
Output is correct |
68 |
Correct |
44 ms |
86444 KB |
Output is correct |
69 |
Correct |
43 ms |
86476 KB |
Output is correct |
70 |
Correct |
44 ms |
86424 KB |
Output is correct |
71 |
Correct |
56 ms |
86632 KB |
Output is correct |
72 |
Correct |
46 ms |
86668 KB |
Output is correct |
73 |
Correct |
50 ms |
86676 KB |
Output is correct |
74 |
Correct |
52 ms |
87492 KB |
Output is correct |
75 |
Correct |
56 ms |
87468 KB |
Output is correct |
76 |
Correct |
89 ms |
87380 KB |
Output is correct |
77 |
Correct |
266 ms |
88676 KB |
Output is correct |
78 |
Correct |
67 ms |
88636 KB |
Output is correct |
79 |
Correct |
144 ms |
88716 KB |
Output is correct |
80 |
Correct |
62 ms |
88736 KB |
Output is correct |
81 |
Correct |
79 ms |
88644 KB |
Output is correct |
82 |
Correct |
243 ms |
88864 KB |
Output is correct |
83 |
Correct |
44 ms |
86496 KB |
Output is correct |
84 |
Correct |
44 ms |
86524 KB |
Output is correct |
85 |
Correct |
60 ms |
86728 KB |
Output is correct |
86 |
Correct |
46 ms |
86684 KB |
Output is correct |
87 |
Correct |
49 ms |
86728 KB |
Output is correct |
88 |
Correct |
49 ms |
87444 KB |
Output is correct |
89 |
Correct |
54 ms |
87796 KB |
Output is correct |
90 |
Correct |
107 ms |
87820 KB |
Output is correct |
91 |
Correct |
296 ms |
89472 KB |
Output is correct |
92 |
Correct |
65 ms |
89280 KB |
Output is correct |
93 |
Correct |
163 ms |
89468 KB |
Output is correct |
94 |
Correct |
46 ms |
86692 KB |
Output is correct |
95 |
Correct |
54 ms |
86724 KB |
Output is correct |
96 |
Correct |
44 ms |
86432 KB |
Output is correct |
97 |
Correct |
44 ms |
86408 KB |
Output is correct |
98 |
Correct |
43 ms |
86420 KB |
Output is correct |
99 |
Correct |
45 ms |
86468 KB |
Output is correct |