# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
166392 | 2019-12-02T04:20:25 Z | Trickster | K blocks (IZhO14_blocks) | C++14 | 487 ms | 2808 KB |
#include <iostream> #include <cstdio> #include <cstdlib> #include <set> #include <map> #include <vector> #include <string> #include <cmath> #include <cstring> #include <queue> #include <stack> #include <algorithm> #include <sstream> #include <numeric> using namespace std; #define f first #define s second #define mp make_pair #define sz(a) int((a).size()) #define pb push_back #define all(c) (c).begin(),(c).end() #define forit(it,S) for(__typeof(S.begin()) it = S.begin(); it != S.end(); ++it) #ifdef WIN32 #define I64d "%I64d" #else #define I64d "%lld" #endif typedef pair <int, int> pi; typedef vector <int> vi; typedef long long ll; const int inf = int(1e9); int n, k; vector <int> prv, cur, a; vector <pi> st; int main() { scanf("%d%d", &n, &k); a.resize(n + 1); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); a[0] = inf; prv.assign(n + 1, inf); prv[0] = 0; cur.resize(n + 1); for (int iter = 1; iter <= k; ++iter) { st.clear(); st.pb(mp(0, prv[0])); cur[0] = inf; for (int i = 1; i <= n; ++i) { int mn = inf; while (a[st.back().f] <= a[i]) { mn = min(mn, st.back().s); st.pop_back(); } cur[i] = min(cur[st.back().f], min(mn, prv[st.back().f]) + a[i]); st.push_back(mp(i, min(mn, prv[i]))); } swap(prv, cur); } cout << prv[n] << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 2 ms | 256 KB | Output is correct |
17 | Correct | 2 ms | 256 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 380 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 4 ms | 256 KB | Output is correct |
16 | Correct | 2 ms | 256 KB | Output is correct |
17 | Correct | 2 ms | 256 KB | Output is correct |
18 | Correct | 2 ms | 256 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 256 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 2 ms | 256 KB | Output is correct |
17 | Correct | 2 ms | 256 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 504 KB | Output is correct |
2 | Correct | 9 ms | 1144 KB | Output is correct |
3 | Correct | 15 ms | 1144 KB | Output is correct |
4 | Correct | 83 ms | 1216 KB | Output is correct |
5 | Correct | 245 ms | 2296 KB | Output is correct |
6 | Correct | 22 ms | 2168 KB | Output is correct |
7 | Correct | 117 ms | 2260 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 256 KB | Output is correct |
11 | Correct | 2 ms | 256 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 3 ms | 376 KB | Output is correct |
14 | Correct | 26 ms | 504 KB | Output is correct |
15 | Correct | 4 ms | 504 KB | Output is correct |
16 | Correct | 10 ms | 576 KB | Output is correct |
17 | Correct | 10 ms | 1144 KB | Output is correct |
18 | Correct | 17 ms | 1144 KB | Output is correct |
19 | Correct | 98 ms | 1272 KB | Output is correct |
20 | Correct | 304 ms | 2168 KB | Output is correct |
21 | Correct | 27 ms | 2168 KB | Output is correct |
22 | Correct | 136 ms | 2244 KB | Output is correct |
23 | Correct | 22 ms | 2168 KB | Output is correct |
24 | Correct | 43 ms | 2168 KB | Output is correct |
25 | Correct | 487 ms | 2168 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 372 KB | Output is correct |
28 | Correct | 24 ms | 504 KB | Output is correct |
29 | Correct | 4 ms | 504 KB | Output is correct |
30 | Correct | 9 ms | 504 KB | Output is correct |
31 | Correct | 10 ms | 1400 KB | Output is correct |
32 | Correct | 16 ms | 1400 KB | Output is correct |
33 | Correct | 87 ms | 1400 KB | Output is correct |
34 | Correct | 250 ms | 2804 KB | Output is correct |
35 | Correct | 23 ms | 2804 KB | Output is correct |
36 | Correct | 122 ms | 2808 KB | Output is correct |
37 | Correct | 4 ms | 504 KB | Output is correct |
38 | Correct | 24 ms | 504 KB | Output is correct |
39 | Correct | 2 ms | 376 KB | Output is correct |
40 | Correct | 2 ms | 376 KB | Output is correct |
41 | Correct | 2 ms | 256 KB | Output is correct |
42 | Correct | 2 ms | 256 KB | Output is correct |