답안 #290344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290344 2020-09-03T16:11:36 Z ngotienhung K개의 묶음 (IZhO14_blocks) C++14
100 / 100
197 ms 42872 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back

using namespace std;

const int maxN = 1e5 + 5;
const int maxK = 105;
const int inf = 1e9 + 10;

int n,k;
int a[maxN], L[maxN], minn[maxN], f[maxK][maxN];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    memset(f, inf, sizeof f);
    f[1][0] = 0;

    for (int i = 1; i <= n; ++i)
        f[1][i] = max(f[1][i - 1], a[i]);

    int tmp;
    for (int i = 2; i <= k; ++i) {
        stack<pair<int, int> > S;
        for (int j = i; j <= n; ++j) {
            int minn = f[i - 1][j - 1];
            while (!S.empty() && a[S.top().se] <= a[j]) {
                minn = min(minn, S.top().fi);
                S.pop();
            }
            if(S.empty()) tmp = 0;
            else tmp = S.top().se;
            f[i][j] = min(f[i][tmp], minn + a[j]);
            S.push({minn, j});
        }
    }
    cout << f[k][n] << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 41472 KB Output is correct
2 Correct 25 ms 41464 KB Output is correct
3 Correct 25 ms 41472 KB Output is correct
4 Correct 25 ms 41464 KB Output is correct
5 Correct 24 ms 41472 KB Output is correct
6 Correct 25 ms 41472 KB Output is correct
7 Correct 27 ms 41468 KB Output is correct
8 Correct 25 ms 41464 KB Output is correct
9 Correct 30 ms 41468 KB Output is correct
10 Correct 25 ms 41472 KB Output is correct
11 Correct 25 ms 41600 KB Output is correct
12 Correct 26 ms 41472 KB Output is correct
13 Correct 25 ms 41472 KB Output is correct
14 Correct 25 ms 41472 KB Output is correct
15 Correct 25 ms 41464 KB Output is correct
16 Correct 25 ms 41472 KB Output is correct
17 Correct 25 ms 41472 KB Output is correct
18 Correct 26 ms 41472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 41472 KB Output is correct
2 Correct 24 ms 41472 KB Output is correct
3 Correct 25 ms 41472 KB Output is correct
4 Correct 25 ms 41472 KB Output is correct
5 Correct 26 ms 41464 KB Output is correct
6 Correct 24 ms 41472 KB Output is correct
7 Correct 24 ms 41472 KB Output is correct
8 Correct 25 ms 41472 KB Output is correct
9 Correct 30 ms 41472 KB Output is correct
10 Correct 25 ms 41464 KB Output is correct
11 Correct 25 ms 41472 KB Output is correct
12 Correct 25 ms 41472 KB Output is correct
13 Correct 25 ms 41472 KB Output is correct
14 Correct 31 ms 41464 KB Output is correct
15 Correct 25 ms 41472 KB Output is correct
16 Correct 25 ms 41468 KB Output is correct
17 Correct 25 ms 41472 KB Output is correct
18 Correct 25 ms 41472 KB Output is correct
19 Correct 25 ms 41464 KB Output is correct
20 Correct 25 ms 41464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 41472 KB Output is correct
2 Correct 27 ms 41464 KB Output is correct
3 Correct 29 ms 41472 KB Output is correct
4 Correct 26 ms 41472 KB Output is correct
5 Correct 24 ms 41464 KB Output is correct
6 Correct 25 ms 41472 KB Output is correct
7 Correct 25 ms 41472 KB Output is correct
8 Correct 24 ms 41472 KB Output is correct
9 Correct 25 ms 41464 KB Output is correct
10 Correct 25 ms 41472 KB Output is correct
11 Correct 26 ms 41464 KB Output is correct
12 Correct 25 ms 41464 KB Output is correct
13 Correct 25 ms 41472 KB Output is correct
14 Correct 24 ms 41472 KB Output is correct
15 Correct 27 ms 41472 KB Output is correct
16 Correct 25 ms 41472 KB Output is correct
17 Correct 25 ms 41472 KB Output is correct
18 Correct 25 ms 41472 KB Output is correct
19 Correct 25 ms 41472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 41600 KB Output is correct
2 Correct 30 ms 41856 KB Output is correct
3 Correct 32 ms 41848 KB Output is correct
4 Correct 69 ms 41984 KB Output is correct
5 Correct 153 ms 42488 KB Output is correct
6 Correct 37 ms 42488 KB Output is correct
7 Correct 88 ms 42488 KB Output is correct
8 Correct 25 ms 41472 KB Output is correct
9 Correct 25 ms 41484 KB Output is correct
10 Correct 25 ms 41464 KB Output is correct
11 Correct 24 ms 41472 KB Output is correct
12 Correct 25 ms 41464 KB Output is correct
13 Correct 24 ms 41472 KB Output is correct
14 Correct 43 ms 41592 KB Output is correct
15 Correct 25 ms 41624 KB Output is correct
16 Correct 31 ms 41592 KB Output is correct
17 Correct 29 ms 41984 KB Output is correct
18 Correct 33 ms 41976 KB Output is correct
19 Correct 83 ms 41976 KB Output is correct
20 Correct 197 ms 42488 KB Output is correct
21 Correct 39 ms 42488 KB Output is correct
22 Correct 107 ms 42488 KB Output is correct
23 Correct 34 ms 42488 KB Output is correct
24 Correct 48 ms 42488 KB Output is correct
25 Correct 193 ms 42488 KB Output is correct
26 Correct 26 ms 41472 KB Output is correct
27 Correct 26 ms 41472 KB Output is correct
28 Correct 39 ms 41592 KB Output is correct
29 Correct 25 ms 41600 KB Output is correct
30 Correct 30 ms 41592 KB Output is correct
31 Correct 29 ms 41976 KB Output is correct
32 Correct 32 ms 42112 KB Output is correct
33 Correct 76 ms 42208 KB Output is correct
34 Correct 177 ms 42872 KB Output is correct
35 Correct 40 ms 42872 KB Output is correct
36 Correct 96 ms 42868 KB Output is correct
37 Correct 25 ms 41600 KB Output is correct
38 Correct 36 ms 41600 KB Output is correct
39 Correct 25 ms 41464 KB Output is correct
40 Correct 24 ms 41472 KB Output is correct
41 Correct 24 ms 41464 KB Output is correct
42 Correct 25 ms 41488 KB Output is correct