답안 #871939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871939 2023-11-12T01:54:24 Z 12345678 K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 4596 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5, kx=105, lx=17;
int n, k, v[nx], dp[kx][nx], mx;

void solve(int l, int r, int ly, int optl, int optr)
{
    if (r<l) return;
    int md=(l+r)/2;
    pair<int, int> p={1e9, -1};
    mx=0;
    for (int i=min(optr, md); i>=optl; i--) mx=max(mx, v[i]), p=min(p, {mx+dp[ly-1][i-1], i});
    dp[ly][md]=p.first;
    solve(l, md-1, ly, optl, p.second);
    solve(md+1, r, ly, p.second, optr);
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>k;
    for (int i=1; i<=n; i++) cin>>v[i], dp[0][i]=1e9;
    for (int i=1; i<=k; i++) dp[i][0]=1e9, solve(1, n, i, 1, n);
    cout<<dp[k][n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4596 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -