Submission #871939

# Submission time Handle Problem Language Result Execution time Memory
871939 2023-11-12T01:54:24 Z 12345678 K blocks (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];
}
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 -