Submission #285425

# Submission time Handle Problem Language Result Execution time Memory
285425 2020-08-28T22:53:07 Z loideptrai1 K blocks (IZhO14_blocks) C++14
100 / 100
246 ms 42280 KB
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define name ""
#define inout freopen(name".inp","r", stdin); freopen(name".out","w",stdout);

using namespace std;

const int N=1e5+5;
const int MOD=1e9+7;
const int base=257;
const int M=1e6+1;
const int INFI=1e9;

int a[N], dp[105][N];
int n,k;
int main()
{
   cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    memset(dp, 0x3f, sizeof dp);
    dp[1][0] = 0;
    for (int i = 1; i <= n; ++i) dp[1][i] = max(dp[1][i - 1], a[i]);
    for (int i = 2; i <= k; ++i) {
        stack<pair<int, int> > S;
        for (int j = i; j <= n; ++j) {
            int minF = dp[i - 1][j - 1];
            while (!S.empty() && a[S.top().second] <= a[j]) {
                minF = min(minF, S.top().first);
                S.pop();
            }
            dp[i][j] = min(dp[i][S.empty() ? 0 : S.top().second], minF + a[j]);
            S.push(make_pair(minF, j));
        }
    }
    cout << dp[k][n] << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 22 ms 41472 KB Output is correct
2 Correct 22 ms 41472 KB Output is correct
3 Correct 22 ms 41472 KB Output is correct
4 Correct 22 ms 41472 KB Output is correct
5 Correct 22 ms 41472 KB Output is correct
6 Correct 22 ms 41464 KB Output is correct
7 Correct 22 ms 41472 KB Output is correct
8 Correct 22 ms 41472 KB Output is correct
9 Correct 22 ms 41472 KB Output is correct
10 Correct 22 ms 41472 KB Output is correct
11 Correct 21 ms 41464 KB Output is correct
12 Correct 22 ms 41472 KB Output is correct
13 Correct 22 ms 41464 KB Output is correct
14 Correct 22 ms 41472 KB Output is correct
15 Correct 22 ms 41472 KB Output is correct
16 Correct 22 ms 41472 KB Output is correct
17 Correct 23 ms 41472 KB Output is correct
18 Correct 22 ms 41464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 41472 KB Output is correct
2 Correct 22 ms 41460 KB Output is correct
3 Correct 26 ms 41472 KB Output is correct
4 Correct 23 ms 41472 KB Output is correct
5 Correct 22 ms 41472 KB Output is correct
6 Correct 25 ms 41464 KB Output is correct
7 Correct 23 ms 41464 KB Output is correct
8 Correct 25 ms 41472 KB Output is correct
9 Correct 23 ms 41472 KB Output is correct
10 Correct 22 ms 41472 KB Output is correct
11 Correct 22 ms 41464 KB Output is correct
12 Correct 22 ms 41472 KB Output is correct
13 Correct 22 ms 41472 KB Output is correct
14 Correct 22 ms 41472 KB Output is correct
15 Correct 25 ms 41472 KB Output is correct
16 Correct 23 ms 41472 KB Output is correct
17 Correct 22 ms 41472 KB Output is correct
18 Correct 22 ms 41472 KB Output is correct
19 Correct 22 ms 41472 KB Output is correct
20 Correct 22 ms 41472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 41472 KB Output is correct
2 Correct 22 ms 41344 KB Output is correct
3 Correct 23 ms 41472 KB Output is correct
4 Correct 22 ms 41472 KB Output is correct
5 Correct 22 ms 41472 KB Output is correct
6 Correct 22 ms 41472 KB Output is correct
7 Correct 22 ms 41344 KB Output is correct
8 Correct 22 ms 41472 KB Output is correct
9 Correct 23 ms 41464 KB Output is correct
10 Correct 22 ms 41472 KB Output is correct
11 Correct 22 ms 41472 KB Output is correct
12 Correct 22 ms 41472 KB Output is correct
13 Correct 29 ms 41472 KB Output is correct
14 Correct 22 ms 41472 KB Output is correct
15 Correct 22 ms 41376 KB Output is correct
16 Correct 22 ms 41464 KB Output is correct
17 Correct 23 ms 41472 KB Output is correct
18 Correct 23 ms 41472 KB Output is correct
19 Correct 23 ms 41504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 41464 KB Output is correct
2 Correct 50 ms 41592 KB Output is correct
3 Correct 60 ms 41592 KB Output is correct
4 Correct 89 ms 41592 KB Output is correct
5 Correct 206 ms 41976 KB Output is correct
6 Correct 86 ms 41848 KB Output is correct
7 Correct 142 ms 41848 KB Output is correct
8 Correct 23 ms 41472 KB Output is correct
9 Correct 22 ms 41472 KB Output is correct
10 Correct 23 ms 41472 KB Output is correct
11 Correct 23 ms 41472 KB Output is correct
12 Correct 23 ms 41472 KB Output is correct
13 Correct 23 ms 41472 KB Output is correct
14 Correct 44 ms 41472 KB Output is correct
15 Correct 29 ms 41472 KB Output is correct
16 Correct 33 ms 41472 KB Output is correct
17 Correct 55 ms 41592 KB Output is correct
18 Correct 53 ms 41592 KB Output is correct
19 Correct 102 ms 41592 KB Output is correct
20 Correct 241 ms 41848 KB Output is correct
21 Correct 88 ms 41848 KB Output is correct
22 Correct 156 ms 41724 KB Output is correct
23 Correct 84 ms 41848 KB Output is correct
24 Correct 99 ms 41848 KB Output is correct
25 Correct 246 ms 41848 KB Output is correct
26 Correct 23 ms 41472 KB Output is correct
27 Correct 23 ms 41472 KB Output is correct
28 Correct 43 ms 41464 KB Output is correct
29 Correct 28 ms 41600 KB Output is correct
30 Correct 32 ms 41472 KB Output is correct
31 Correct 49 ms 41592 KB Output is correct
32 Correct 53 ms 41720 KB Output is correct
33 Correct 94 ms 41764 KB Output is correct
34 Correct 224 ms 42140 KB Output is correct
35 Correct 95 ms 42232 KB Output is correct
36 Correct 150 ms 42280 KB Output is correct
37 Correct 28 ms 41472 KB Output is correct
38 Correct 41 ms 41600 KB Output is correct
39 Correct 23 ms 41472 KB Output is correct
40 Correct 23 ms 41472 KB Output is correct
41 Correct 22 ms 41472 KB Output is correct
42 Correct 22 ms 41472 KB Output is correct