답안 #142412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
142412 2019-08-09T05:22:44 Z meatrow K개의 묶음 (IZhO14_blocks) C++17
100 / 100
181 ms 41532 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 1e5 + 5;
const int K = 105;

int dp[K][N];
int a[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        dp[1][i] = max(dp[1][i - 1], a[i]);
    }
    for (int i = 2; i <= k; i++) {
        vector<pair<int, int>> kek;
        for (int j = 1; j <= n; j++) {
            int cur = dp[i - 1][j - 1];
            if (!cur) {
                cur = 1e9;
            }
            while (!kek.empty() && kek.back().first < a[j]) {
                cur = min(cur, kek.back().second);
                kek.pop_back();
            }
            if (kek.empty() || a[j] + cur < kek.back().first + kek.back().second) {
                kek.emplace_back(a[j], cur);
            }
            dp[i][j] = kek.back().first + kek.back().second;
        }
    }
    cout << dp[k][n];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 376 KB Output is correct
5 Correct 2 ms 376 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 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 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 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 296 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 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 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 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 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 888 KB Output is correct
16 Correct 2 ms 888 KB Output is correct
17 Correct 2 ms 680 KB Output is correct
18 Correct 2 ms 888 KB Output is correct
19 Correct 2 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 8 ms 1016 KB Output is correct
3 Correct 10 ms 2168 KB Output is correct
4 Correct 39 ms 14352 KB Output is correct
5 Correct 109 ms 40612 KB Output is correct
6 Correct 16 ms 2576 KB Output is correct
7 Correct 56 ms 19064 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 424 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 14 ms 4856 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 6 ms 1528 KB Output is correct
17 Correct 8 ms 1016 KB Output is correct
18 Correct 10 ms 2040 KB Output is correct
19 Correct 40 ms 14328 KB Output is correct
20 Correct 104 ms 40568 KB Output is correct
21 Correct 16 ms 2524 KB Output is correct
22 Correct 55 ms 19076 KB Output is correct
23 Correct 14 ms 1784 KB Output is correct
24 Correct 22 ms 5368 KB Output is correct
25 Correct 109 ms 40596 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 504 KB Output is correct
28 Correct 16 ms 4984 KB Output is correct
29 Correct 4 ms 632 KB Output is correct
30 Correct 7 ms 1656 KB Output is correct
31 Correct 8 ms 1016 KB Output is correct
32 Correct 12 ms 2536 KB Output is correct
33 Correct 78 ms 14820 KB Output is correct
34 Correct 181 ms 41532 KB Output is correct
35 Correct 18 ms 3156 KB Output is correct
36 Correct 87 ms 19912 KB Output is correct
37 Correct 4 ms 508 KB Output is correct
38 Correct 13 ms 4860 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 2 ms 504 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct