답안 #817680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817680 2023-08-09T15:00:21 Z vjudge1 K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 316 KB
#include <bits/stdc++.h>
using namespace std;

int32_t main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        int n, k;
        cin >> n >> k;
        vector<int> a(n + 1);
        for (int i = 1; i <= n; i++) cin >> a[i];
        vector<int64_t> f(n + 1, 0);
        for (int i = 1; i <= n; i++) f[i] = max<int64_t>(f[i - 1], a[i]);
        vector<int64_t> g(n + 1);
        f[0] = 0;
        for (int i = 1; i < k; i++) {
                vector<int64_t> nf(n + 1, 1e18);
                stack<int> st;
                for (int j = 1; j <= n; j++) {
                        int64_t mn = 1e18;
                        while (st.size() && a[st.top()] <= a[j]) {
                                mn = min(mn, g[st.top()]);
                                st.pop();
                        }
                        if (st.size()) nf[j] = min(f[st.top()], nf[st.top()] + a[j]);
                        nf[j] = min(nf[j], mn + a[j]);
                        g[j] = min(f[j], mn);
                        st.emplace(j);
                }
                f = nf;
        }
        cout << f[n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 232 KB Output is correct
2 Correct 1 ms 232 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -