답안 #885106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885106 2023-12-09T02:35:26 Z votranngocvy K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1 ms 2512 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N = 1e5 + 5;
const int inf = 0x3f3f3f3f3f3f3f3f;
int a[N],st[4 * N],n,k,dp[N][105];

void build(int id,int l,int r) {
    if (l == r) {
        st[id] = a[l];
        return;
    }
    int mid = (l + r) / 2;
    build(id * 2,l,mid);
    build(id * 2 + 1,mid + 1,r);
    st[id] = max(st[id * 2],st[id * 2 + 1]);
}

int get(int id,int l,int r,int u,int v) {
    if (v < l || r < u) return -inf;
    if (u <= l && r <= v) return st[id];
    int mid = (l + r) / 2;
    return max(get(id * 2,l,mid,u,v),get(id * 2 + 1,mid + 1,r,u,v));
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    build(1,1,n);
    for (int i = 0; i <= k; i++)
        for (int j = 0; j <= n; j++) dp[i][j] = inf;
    dp[0][0] = 0;
    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= n; j++)
            for (int z = 0; z < i; z++)
                dp[i][j] = min(dp[i][j],dp[i - 1][z] + get(1,1,n,z + 1,j));
    cout << dp[k][n] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2512 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Incorrect 0 ms 2396 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Incorrect 1 ms 2396 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2512 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Incorrect 0 ms 2396 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2512 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Incorrect 0 ms 2396 KB Output isn't correct
9 Halted 0 ms 0 KB -