Submission #102684

# Submission time Handle Problem Language Result Execution time Memory
102684 2019-03-26T18:14:02 Z brcode K blocks (IZhO14_blocks) C++14
0 / 100
33 ms 9380 KB
#include <iostream>

using namespace std;
//dp[n][k] = max for n blocks with k partitions
//dp[n][k] = max(dp[n][k],dp[j][k-1]+maxquery(j+1,n))

const int MAXN = 1e5+5;
int arr[MAXN];
pair<int,int> tree2[110][10*MAXN];
int tree[10*MAXN];
int dp[MAXN][110];
void build(int curr,int l,int r){
    if(l==r){
        tree[curr] = arr[l];
    }else{
        int mid = (l+r)/2;
        build(2*curr,1,mid);
        build(2*curr+1,mid+1,r);
        tree[curr] = max(tree[2*curr],tree[2*curr+1]);
    }
}
int maxquery(int curr,int l,int r,int tl,int tr){
    if(l>tr||r<tl){
        return 0;
    }else if(l>=tl && r<=tr){
        return tree[curr];
    }else{
        int mid = (l+r)/2;
        return max(maxquery(2*curr,1,mid,tl,tr),maxquery(2*curr+1,mid+1,r,tl,tr));
    }
}
void build2(int k,int curr,int l,int r){
    if(l == r){
        tree2[k][curr] = make_pair(dp[k][l],-1*l);
    }else{
        int mid = (l+r)/2;
        build2(k,curr*2,l,mid);
        build2(k,2*curr+1,mid+1,r);
        tree2[k][curr] = min(tree2[k][2*curr],tree2[k][2*curr+1]);
    }
}
pair<int,int> minquery(int k,int curr,int l,int r,int tl,int tr){
    if(l>tr||r<tl){
        return make_pair(1e9,1e9);
    }else if(l>=tl && r<=tr){
        return tree2[k][curr];
    }else{
        int mid = (l+r)/2;
        return min(minquery(k,2*curr,1,mid,tl,tr),minquery(k,2*curr+1,mid+1,r,tl,tr));
    }
}
void update(int k,int val,int pos,int curr,int l,int r){
    if(l == r){
        tree2[k][curr] = make_pair(val,-1*l);
    }else{
        int mid =(l+r)/2;
        if(pos>=l && pos<=mid){
            update(k,val,pos,2*curr,l,mid);
        }else{
            update(k,val,pos,2*curr+1,mid+1,r);
        }
        tree2[k][curr] = min(tree2[k][2*curr],tree2[k][2*curr+1]);
    }
}
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            dp[i][j] = 1e9;
        }
    }
    build(1,1,n);
    
    dp[1][1] = arr[1];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            auto hold = minquery(j-1,1,1,n,1,i-1);
            int one = hold.first;
            int from = -1*hold.second;
            dp[i][j] = min(dp[i][j],one+maxquery(1,1,n,from+1,i));
            //int k,int val,int pos,int curr,int l,int r
            update(j,dp[i][j],i,1,1,n);
        }
    }
    cout<<dp[n][k]<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Incorrect 2 ms 512 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Incorrect 2 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 9380 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -