답안 #337577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337577 2020-12-21T06:49:22 Z BY_KUTBILIM K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1 ms 364 KB
/** @BY_KUTBILIM **/
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back  
#define ll long long

const int inf = (int)1e9+7;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie();

    int n, k;
    cin >> n >> k;
    int a[n+1];
    int dp[n+1][k+1];
    
    for(int i = 1; i <= n; i++)cin >> a[i];
    
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= k; j++){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;
    dp[1][1] = a[1];
    for(int i = 2; i <= n; i++){
        dp[i][1] = max(dp[i-1][1], a[i]);
    }
    
    for(int block = 2; block <= k; block++){
        stack<pair<int,int>> st;
        
        for(int i = 1; i <= n; i++){
            int mn = dp[i-1][k-1];
            while(!st.empty() and a[st.top().first] <= a[i]){
                mn = min(mn, st.top().second);
                st.pop();
            }
            if(!st.empty()){
                dp[i][k] = min(dp[i][k], dp[st.top().first][k]);
            }
            dp[i][k] = min(dp[i][k], mn + a[i]);
            st.push({i, mn});
        }
    }
    cout << dp[n][k];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -