답안 #736400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
736400 2023-05-05T14:41:44 Z cdjs1432 K개의 묶음 (IZhO14_blocks) C++17
0 / 100
20 ms 40288 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;


int a[100005];
int dp[100005][102];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);
    
    memset(dp,0x3f,sizeof(dp));
    int n, k;
    cin >> n >> k;
    int maxx = 0;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
        dp[i][1] = maxx = max(a[i], maxx);
    }
    
    for (int i=2; i<=k; i++) {
        stack<pair<int, int>> s;
        for (int j=1; j<=n; j++) {
            int best = dp[j-1][i-1];
            while (!s.empty() && a[s.top().second] <= a[j]) {
                best = min(best, s.top().first);
                s.pop();
            }
            if (s.empty())  dp[j][i] = best + a[j];
            else    dp[j][i] = min(best + a[j], dp[s.top().second][i-1]);
            s.push({best, j});
        }
    }
    cout << dp[n][k];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 40148 KB Output is correct
2 Correct 16 ms 40148 KB Output is correct
3 Correct 16 ms 40208 KB Output is correct
4 Correct 17 ms 40148 KB Output is correct
5 Incorrect 17 ms 40288 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 40228 KB Output is correct
2 Correct 16 ms 40148 KB Output is correct
3 Correct 18 ms 40252 KB Output is correct
4 Correct 17 ms 40220 KB Output is correct
5 Incorrect 18 ms 40148 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 40148 KB Output is correct
2 Correct 16 ms 40148 KB Output is correct
3 Correct 16 ms 40208 KB Output is correct
4 Correct 17 ms 40148 KB Output is correct
5 Incorrect 17 ms 40288 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 40148 KB Output is correct
2 Correct 16 ms 40148 KB Output is correct
3 Correct 16 ms 40208 KB Output is correct
4 Correct 17 ms 40148 KB Output is correct
5 Incorrect 17 ms 40288 KB Output isn't correct
6 Halted 0 ms 0 KB -