# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
872950 |
2023-11-14T07:10:22 Z |
nasam |
K blocks (IZhO14_blocks) |
C++17 |
|
179 ms |
81748 KB |
/*************************************
* author: Pham Huy Khanh *
*************************************/
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define FOD(i,b,a) for (int i = (b), _a = (a); i >= _a; i--)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define CNTBIT(x) __builtin_popcount(x)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define left ___left
#define right ___right
#define pii pair<int, int>
#define DEBUG(n, a) FOR (i, 1, n) cout << a[i] << ' '; cout << endl;
#define lob lower_bound // >=
#define upb upper_bound // >
#define endl "\n"
using namespace std;
template<class X, class Y> bool maximize(X &x, Y y){ if (x < y){ x = y; return true; } return false; }
template<class X, class Y> bool minimize(X &x, Y y){ if (x > y){ x = y; return true; } return false; }
#define gogobruhbruh ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
const int MOD = 1e9 + 7;
void add(int &a, int b){ if ((a += b) >= MOD) a -= MOD; }
void sub(int &a, int b){ if ((a -= b) < 0) a += MOD - 1; }
int muti(int a, int b){ return (1LL * a * b) % MOD; }
int Pow(int x, int y){ int res = 1; for (; y; y >>= 1){ if (y & 1) res = muti(res, x); x = muti(x, x); } return res; }
int Pow2(int x, int y){ int res = 1; for (; y; y >>= 1){ if (y & 1) res = 1LL * res * x % (MOD - 1); x = 1LL * x * x % (MOD - 1); } return res; }
const int MAX = 1e5 + 2;
const int K = 1e2 + 2;
const int INF = 2e9 + 7;
int num, lim;
int a[MAX];
ll dp[MAX][K];
stack<pii> st;
void solve(){
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
FOR (j, 1, lim){
while (st.size())
st.pop();
FOR (i, 1, num){
ll Min = dp[i - 1][j - 1];
while (st.size() && a[st.top().se] <= a[i])
minimize(Min, st.top().fi),
st.pop();
int L = st.empty() ? 0 : st.top().se;
dp[i][j] = min(dp[L][j], Min + a[i]);
st.push({Min, i});
}
}
cout << dp[num][lim];
}
void read(){
cin >> num >> lim;
FOR (i, 1, num)
cin >> a[i];
}
int main(){
gogobruhbruh;
file("main");
int test = 1;
// cin >> test;
while (test--)
read(),
solve();
}
Compilation message
blocks.cpp: In function 'int main()':
blocks.cpp:31:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:77:5: note: in expansion of macro 'file'
77 | file("main");
| ^~~~
blocks.cpp:31:95: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:77:5: note: in expansion of macro 'file'
77 | file("main");
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
80472 KB |
Output is correct |
2 |
Correct |
10 ms |
80728 KB |
Output is correct |
3 |
Correct |
10 ms |
80472 KB |
Output is correct |
4 |
Correct |
10 ms |
80552 KB |
Output is correct |
5 |
Correct |
10 ms |
80476 KB |
Output is correct |
6 |
Correct |
10 ms |
80548 KB |
Output is correct |
7 |
Correct |
10 ms |
80576 KB |
Output is correct |
8 |
Correct |
10 ms |
80476 KB |
Output is correct |
9 |
Correct |
10 ms |
80476 KB |
Output is correct |
10 |
Correct |
10 ms |
80476 KB |
Output is correct |
11 |
Correct |
10 ms |
80476 KB |
Output is correct |
12 |
Correct |
10 ms |
80552 KB |
Output is correct |
13 |
Correct |
10 ms |
80476 KB |
Output is correct |
14 |
Correct |
9 ms |
80640 KB |
Output is correct |
15 |
Correct |
10 ms |
80568 KB |
Output is correct |
16 |
Correct |
10 ms |
80472 KB |
Output is correct |
17 |
Correct |
9 ms |
80472 KB |
Output is correct |
18 |
Correct |
10 ms |
80476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
80476 KB |
Output is correct |
2 |
Correct |
10 ms |
80572 KB |
Output is correct |
3 |
Correct |
10 ms |
80472 KB |
Output is correct |
4 |
Correct |
10 ms |
80556 KB |
Output is correct |
5 |
Correct |
10 ms |
80476 KB |
Output is correct |
6 |
Correct |
10 ms |
80548 KB |
Output is correct |
7 |
Correct |
10 ms |
80476 KB |
Output is correct |
8 |
Correct |
10 ms |
80472 KB |
Output is correct |
9 |
Correct |
10 ms |
80728 KB |
Output is correct |
10 |
Correct |
10 ms |
80476 KB |
Output is correct |
11 |
Correct |
10 ms |
80476 KB |
Output is correct |
12 |
Correct |
10 ms |
80656 KB |
Output is correct |
13 |
Correct |
10 ms |
80636 KB |
Output is correct |
14 |
Correct |
10 ms |
80668 KB |
Output is correct |
15 |
Correct |
10 ms |
80476 KB |
Output is correct |
16 |
Correct |
10 ms |
80572 KB |
Output is correct |
17 |
Correct |
11 ms |
80472 KB |
Output is correct |
18 |
Correct |
10 ms |
80476 KB |
Output is correct |
19 |
Correct |
12 ms |
80588 KB |
Output is correct |
20 |
Correct |
10 ms |
80476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
80472 KB |
Output is correct |
2 |
Correct |
10 ms |
80728 KB |
Output is correct |
3 |
Correct |
10 ms |
80472 KB |
Output is correct |
4 |
Correct |
10 ms |
80552 KB |
Output is correct |
5 |
Correct |
10 ms |
80476 KB |
Output is correct |
6 |
Correct |
10 ms |
80548 KB |
Output is correct |
7 |
Correct |
10 ms |
80576 KB |
Output is correct |
8 |
Correct |
10 ms |
80476 KB |
Output is correct |
9 |
Correct |
10 ms |
80476 KB |
Output is correct |
10 |
Correct |
10 ms |
80476 KB |
Output is correct |
11 |
Correct |
10 ms |
80476 KB |
Output is correct |
12 |
Correct |
10 ms |
80552 KB |
Output is correct |
13 |
Correct |
10 ms |
80476 KB |
Output is correct |
14 |
Correct |
9 ms |
80640 KB |
Output is correct |
15 |
Correct |
10 ms |
80568 KB |
Output is correct |
16 |
Correct |
10 ms |
80472 KB |
Output is correct |
17 |
Correct |
9 ms |
80472 KB |
Output is correct |
18 |
Correct |
10 ms |
80476 KB |
Output is correct |
19 |
Correct |
11 ms |
80476 KB |
Output is correct |
20 |
Correct |
10 ms |
80572 KB |
Output is correct |
21 |
Correct |
10 ms |
80472 KB |
Output is correct |
22 |
Correct |
10 ms |
80556 KB |
Output is correct |
23 |
Correct |
10 ms |
80476 KB |
Output is correct |
24 |
Correct |
10 ms |
80548 KB |
Output is correct |
25 |
Correct |
10 ms |
80476 KB |
Output is correct |
26 |
Correct |
10 ms |
80472 KB |
Output is correct |
27 |
Correct |
10 ms |
80728 KB |
Output is correct |
28 |
Correct |
10 ms |
80476 KB |
Output is correct |
29 |
Correct |
10 ms |
80476 KB |
Output is correct |
30 |
Correct |
10 ms |
80656 KB |
Output is correct |
31 |
Correct |
10 ms |
80636 KB |
Output is correct |
32 |
Correct |
10 ms |
80668 KB |
Output is correct |
33 |
Correct |
10 ms |
80476 KB |
Output is correct |
34 |
Correct |
10 ms |
80572 KB |
Output is correct |
35 |
Correct |
11 ms |
80472 KB |
Output is correct |
36 |
Correct |
10 ms |
80476 KB |
Output is correct |
37 |
Correct |
12 ms |
80588 KB |
Output is correct |
38 |
Correct |
10 ms |
80476 KB |
Output is correct |
39 |
Correct |
11 ms |
80476 KB |
Output is correct |
40 |
Correct |
10 ms |
80588 KB |
Output is correct |
41 |
Correct |
10 ms |
80596 KB |
Output is correct |
42 |
Correct |
10 ms |
80476 KB |
Output is correct |
43 |
Correct |
11 ms |
80476 KB |
Output is correct |
44 |
Correct |
9 ms |
80476 KB |
Output is correct |
45 |
Correct |
10 ms |
80476 KB |
Output is correct |
46 |
Correct |
10 ms |
80548 KB |
Output is correct |
47 |
Correct |
11 ms |
80608 KB |
Output is correct |
48 |
Correct |
10 ms |
80476 KB |
Output is correct |
49 |
Correct |
9 ms |
80584 KB |
Output is correct |
50 |
Correct |
10 ms |
80472 KB |
Output is correct |
51 |
Correct |
10 ms |
80476 KB |
Output is correct |
52 |
Correct |
10 ms |
80732 KB |
Output is correct |
53 |
Correct |
10 ms |
80476 KB |
Output is correct |
54 |
Correct |
10 ms |
80476 KB |
Output is correct |
55 |
Correct |
10 ms |
80472 KB |
Output is correct |
56 |
Correct |
10 ms |
80664 KB |
Output is correct |
57 |
Correct |
10 ms |
80476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
80472 KB |
Output is correct |
2 |
Correct |
10 ms |
80728 KB |
Output is correct |
3 |
Correct |
10 ms |
80472 KB |
Output is correct |
4 |
Correct |
10 ms |
80552 KB |
Output is correct |
5 |
Correct |
10 ms |
80476 KB |
Output is correct |
6 |
Correct |
10 ms |
80548 KB |
Output is correct |
7 |
Correct |
10 ms |
80576 KB |
Output is correct |
8 |
Correct |
10 ms |
80476 KB |
Output is correct |
9 |
Correct |
10 ms |
80476 KB |
Output is correct |
10 |
Correct |
10 ms |
80476 KB |
Output is correct |
11 |
Correct |
10 ms |
80476 KB |
Output is correct |
12 |
Correct |
10 ms |
80552 KB |
Output is correct |
13 |
Correct |
10 ms |
80476 KB |
Output is correct |
14 |
Correct |
9 ms |
80640 KB |
Output is correct |
15 |
Correct |
10 ms |
80568 KB |
Output is correct |
16 |
Correct |
10 ms |
80472 KB |
Output is correct |
17 |
Correct |
9 ms |
80472 KB |
Output is correct |
18 |
Correct |
10 ms |
80476 KB |
Output is correct |
19 |
Correct |
11 ms |
80476 KB |
Output is correct |
20 |
Correct |
10 ms |
80572 KB |
Output is correct |
21 |
Correct |
10 ms |
80472 KB |
Output is correct |
22 |
Correct |
10 ms |
80556 KB |
Output is correct |
23 |
Correct |
10 ms |
80476 KB |
Output is correct |
24 |
Correct |
10 ms |
80548 KB |
Output is correct |
25 |
Correct |
10 ms |
80476 KB |
Output is correct |
26 |
Correct |
10 ms |
80472 KB |
Output is correct |
27 |
Correct |
10 ms |
80728 KB |
Output is correct |
28 |
Correct |
10 ms |
80476 KB |
Output is correct |
29 |
Correct |
10 ms |
80476 KB |
Output is correct |
30 |
Correct |
10 ms |
80656 KB |
Output is correct |
31 |
Correct |
10 ms |
80636 KB |
Output is correct |
32 |
Correct |
10 ms |
80668 KB |
Output is correct |
33 |
Correct |
10 ms |
80476 KB |
Output is correct |
34 |
Correct |
10 ms |
80572 KB |
Output is correct |
35 |
Correct |
11 ms |
80472 KB |
Output is correct |
36 |
Correct |
10 ms |
80476 KB |
Output is correct |
37 |
Correct |
12 ms |
80588 KB |
Output is correct |
38 |
Correct |
10 ms |
80476 KB |
Output is correct |
39 |
Correct |
11 ms |
80476 KB |
Output is correct |
40 |
Correct |
10 ms |
80588 KB |
Output is correct |
41 |
Correct |
10 ms |
80596 KB |
Output is correct |
42 |
Correct |
10 ms |
80476 KB |
Output is correct |
43 |
Correct |
11 ms |
80476 KB |
Output is correct |
44 |
Correct |
9 ms |
80476 KB |
Output is correct |
45 |
Correct |
10 ms |
80476 KB |
Output is correct |
46 |
Correct |
10 ms |
80548 KB |
Output is correct |
47 |
Correct |
11 ms |
80608 KB |
Output is correct |
48 |
Correct |
10 ms |
80476 KB |
Output is correct |
49 |
Correct |
9 ms |
80584 KB |
Output is correct |
50 |
Correct |
10 ms |
80472 KB |
Output is correct |
51 |
Correct |
10 ms |
80476 KB |
Output is correct |
52 |
Correct |
10 ms |
80732 KB |
Output is correct |
53 |
Correct |
10 ms |
80476 KB |
Output is correct |
54 |
Correct |
10 ms |
80476 KB |
Output is correct |
55 |
Correct |
10 ms |
80472 KB |
Output is correct |
56 |
Correct |
10 ms |
80664 KB |
Output is correct |
57 |
Correct |
10 ms |
80476 KB |
Output is correct |
58 |
Correct |
13 ms |
80728 KB |
Output is correct |
59 |
Correct |
15 ms |
80892 KB |
Output is correct |
60 |
Correct |
17 ms |
80972 KB |
Output is correct |
61 |
Correct |
49 ms |
80944 KB |
Output is correct |
62 |
Correct |
179 ms |
81356 KB |
Output is correct |
63 |
Correct |
19 ms |
81232 KB |
Output is correct |
64 |
Correct |
67 ms |
81244 KB |
Output is correct |
65 |
Correct |
10 ms |
80472 KB |
Output is correct |
66 |
Correct |
10 ms |
80476 KB |
Output is correct |
67 |
Correct |
11 ms |
80592 KB |
Output is correct |
68 |
Correct |
10 ms |
80472 KB |
Output is correct |
69 |
Correct |
10 ms |
80476 KB |
Output is correct |
70 |
Correct |
10 ms |
80600 KB |
Output is correct |
71 |
Correct |
23 ms |
80732 KB |
Output is correct |
72 |
Correct |
11 ms |
80592 KB |
Output is correct |
73 |
Correct |
14 ms |
80656 KB |
Output is correct |
74 |
Correct |
14 ms |
80728 KB |
Output is correct |
75 |
Correct |
17 ms |
80728 KB |
Output is correct |
76 |
Correct |
58 ms |
80732 KB |
Output is correct |
77 |
Correct |
154 ms |
81236 KB |
Output is correct |
78 |
Correct |
26 ms |
81264 KB |
Output is correct |
79 |
Correct |
79 ms |
81244 KB |
Output is correct |
80 |
Correct |
18 ms |
81376 KB |
Output is correct |
81 |
Correct |
32 ms |
81244 KB |
Output is correct |
82 |
Correct |
154 ms |
81356 KB |
Output is correct |
83 |
Correct |
10 ms |
80476 KB |
Output is correct |
84 |
Correct |
10 ms |
80476 KB |
Output is correct |
85 |
Correct |
22 ms |
80732 KB |
Output is correct |
86 |
Correct |
11 ms |
80732 KB |
Output is correct |
87 |
Correct |
15 ms |
80732 KB |
Output is correct |
88 |
Correct |
13 ms |
80988 KB |
Output is correct |
89 |
Correct |
16 ms |
81240 KB |
Output is correct |
90 |
Correct |
53 ms |
80988 KB |
Output is correct |
91 |
Correct |
133 ms |
81748 KB |
Output is correct |
92 |
Correct |
21 ms |
81500 KB |
Output is correct |
93 |
Correct |
72 ms |
81532 KB |
Output is correct |
94 |
Correct |
10 ms |
80664 KB |
Output is correct |
95 |
Correct |
21 ms |
80664 KB |
Output is correct |
96 |
Correct |
10 ms |
80476 KB |
Output is correct |
97 |
Correct |
10 ms |
80476 KB |
Output is correct |
98 |
Correct |
10 ms |
80564 KB |
Output is correct |
99 |
Correct |
11 ms |
80624 KB |
Output is correct |