답안 #687538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687538 2023-01-26T14:03:33 Z speedyArda K개의 묶음 (IZhO14_blocks) C++14
0 / 100
31 ms 79372 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const int MAXN = 1e5+5;
ll pref[MAXN], suf[MAXN], in[MAXN];
ll dp[105][MAXN];
ll seg[MAXN * 4];
void build(int v, int l, int r)
{
    if(l == r)
    {
        seg[v] = in[l];
        return;
    }
    int m = (l + r) / 2;

    build(2 * v, l, m);
    build(2 * v + 1, m + 1, r);
    seg[v] = max(seg[v * 2], seg[v * 2 + 1]);
}

ll get(int v, int tl, int tr, int l, int r)
{
    if(l > r)
        return 0;
    if(l == tl && tr == r)
        return seg[v];
    int tm = (tl + tr) / 2;
    return max(get(2 * v, tl, tm, l, min(tm, r)), get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}

int main() 
{
    int n, k;
    cin >> n >> k;
    vector<int> max_idx;
    pref[0] = suf[n+1] = 0;
    for(int i = 0; i <= 100; i++)
        for(int a = 0; a <= 1e5; a++)
            dp[i][a] = 1e18;
    for(int i = 1; i <= n; i++) {
        cin >> in[i];

    }
    build(1, 1, n);
    //cout << "hm\n";
    for(int i = 0; i <= n; i++)
        dp[0][i] = 0;
    for(int idx = 1; idx <= n; idx++)
    {
        for(int block = 1; block <= k; block++)
        {
            for(int left = 0; left < idx; left++) {
                dp[block][idx] = min(dp[block][idx], get(1, 1, n, left + 1, idx) + dp[block - 1][left]);
            }
        }
    }
    cout << dp[k][n] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 79324 KB Output is correct
2 Incorrect 31 ms 79368 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 79372 KB Output is correct
2 Incorrect 31 ms 79292 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 79324 KB Output is correct
2 Incorrect 31 ms 79368 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 79324 KB Output is correct
2 Incorrect 31 ms 79368 KB Output isn't correct
3 Halted 0 ms 0 KB -