답안 #311842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
311842 2020-10-12T00:12:49 Z nikatamliani K개의 묶음 (IZhO14_blocks) C++14
0 / 100
25 ms 35712 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 3005, oo = 1e9;
int n, k, a[N], dp[N][N];
int main() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            dp[i][j] = oo;
        }
    }
    stack < int > st;
    dp[0][0] = 0;
    for(int i = 1; i <= n; ++i) {
        while(!st.empty() && a[st.top()] <= a[i]) st.pop();
        int x = 0;
        if(!st.empty()) x = st.top();
        for(int j = 1; j <= min(i, k); ++j) {
            dp[i][j] = min(dp[x][j], dp[x][j - 1] + a[i]);
        }
        st.push(i);
    }
    cout << dp[n][k] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 35704 KB Output is correct
2 Correct 22 ms 35712 KB Output is correct
3 Correct 22 ms 35704 KB Output is correct
4 Incorrect 22 ms 35712 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 35712 KB Output is correct
2 Correct 22 ms 35712 KB Output is correct
3 Correct 24 ms 35712 KB Output is correct
4 Incorrect 23 ms 35704 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 35704 KB Output is correct
2 Correct 22 ms 35712 KB Output is correct
3 Correct 22 ms 35704 KB Output is correct
4 Incorrect 22 ms 35712 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 35704 KB Output is correct
2 Correct 22 ms 35712 KB Output is correct
3 Correct 22 ms 35704 KB Output is correct
4 Incorrect 22 ms 35712 KB Output isn't correct
5 Halted 0 ms 0 KB -