Submission #799674

# Submission time Handle Problem Language Result Execution time Memory
799674 2023-07-31T19:21:02 Z Ahmed57 K blocks (IZhO14_blocks) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>

using namespace std;
long long dp[3001][3001];
long long arr[3001];
long long qu(int l,int r){
    long long ma = 0;
    for(int i = l;i<=r;i++){
        ma = max(ma,arr[i]);
    }
    return ma;
}
void dc(int i,int l,int r,int optl,int optr){
    if(l>r)return;
    int mid = (l+r)/2;
    pair<long long,int> best = {1e18,0};
    for(int cut = optl;cut<min(mid,optr+1);cut++){
        long long sum = qu(cut+1,mid);
        best = min(best,make_pair(sum+dp[i-1][cut],cut));
    }
    dp[i][mid] = best.first;
    int opt = best.second;
    if(l==r)return;
    dc(i,l,mid,optl,opt);
    dc(i,mid+1,r,opt,optr);
}
int main(){
    //ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i = 1;i<=n;i++){
        cin>>arr[i];
    }
    for(int i = 1;i<=n;i++)dp[0][i] = 1e18;
    dp[0][0] = 0;
    for(int i = 1;i<=k;i++){
        dc(i,1,n,0,n-1);
        for(int e= 0;e<i;e++){
            dp[i][e] = 1e18;
        }
    }
    cout<<dp[k][n]<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -