Submission #1101631

# Submission time Handle Problem Language Result Execution time Memory
1101631 2024-10-16T12:11:20 Z ngongocbich K blocks (IZhO14_blocks) C++17
0 / 100
11 ms 82684 KB
#include <bits/stdc++.h>
#define int long long
#define mask(k) (1<<(k))
using namespace std;
int n,k,a[100001],dp[100001][101],l[100001],mx[100001][21];
stack<int> st;
int getmn(int l, int r)
{
    int p=__lg(r-l+1);
    return min(mx[l][p],mx[r-mask(p)+1][p]);
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen("kblocks.inp","r",stdin);
    //freopen("kblocks.out","w",stdout);
    cin>>n>>k;
    for (int i=1; i<=n; i++) cin>>a[i];
    for (int i=1; i<=n; i++)
    {
        while (!st.empty() && a[st.top()]<=a[i]) st.pop();
        if (!st.empty()) l[i]=st.top(); else l[i]=0;
        st.push(i);
    }
    memset(dp,0x3f,sizeof(dp));
    dp[0][0]=0;
    for (int j=1; j<=k; j++)
    {
        for (int i=0; i<=n; i++) mx[i][0]=dp[i][j-1];
        for (int j=1; mask(j)<=n+1; j++)
            for (int i=0; i+mask(j)-1<=n; i++)
                mx[i][j]=min(mx[i][j-1],mx[i+mask(j-1)][j-1]);
        for (int i=1; i<=n; i++)
        {
            dp[i][j]=min(dp[i][j],getmn(l[i],i)+a[i]);
            dp[i][j]=min(dp[i][j],dp[l[i]][j]);
        }
    }
    cout<<dp[n][k];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 82512 KB Output is correct
2 Correct 10 ms 82680 KB Output is correct
3 Correct 10 ms 82512 KB Output is correct
4 Correct 10 ms 82512 KB Output is correct
5 Correct 10 ms 82512 KB Output is correct
6 Correct 10 ms 82496 KB Output is correct
7 Correct 10 ms 82524 KB Output is correct
8 Correct 10 ms 82512 KB Output is correct
9 Correct 10 ms 82512 KB Output is correct
10 Incorrect 10 ms 82512 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 82512 KB Output is correct
2 Correct 10 ms 82424 KB Output is correct
3 Correct 10 ms 82512 KB Output is correct
4 Correct 10 ms 82512 KB Output is correct
5 Correct 10 ms 82512 KB Output is correct
6 Correct 10 ms 82512 KB Output is correct
7 Correct 10 ms 82512 KB Output is correct
8 Correct 11 ms 82512 KB Output is correct
9 Correct 10 ms 82512 KB Output is correct
10 Incorrect 10 ms 82684 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 82512 KB Output is correct
2 Correct 10 ms 82680 KB Output is correct
3 Correct 10 ms 82512 KB Output is correct
4 Correct 10 ms 82512 KB Output is correct
5 Correct 10 ms 82512 KB Output is correct
6 Correct 10 ms 82496 KB Output is correct
7 Correct 10 ms 82524 KB Output is correct
8 Correct 10 ms 82512 KB Output is correct
9 Correct 10 ms 82512 KB Output is correct
10 Incorrect 10 ms 82512 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 82512 KB Output is correct
2 Correct 10 ms 82680 KB Output is correct
3 Correct 10 ms 82512 KB Output is correct
4 Correct 10 ms 82512 KB Output is correct
5 Correct 10 ms 82512 KB Output is correct
6 Correct 10 ms 82496 KB Output is correct
7 Correct 10 ms 82524 KB Output is correct
8 Correct 10 ms 82512 KB Output is correct
9 Correct 10 ms 82512 KB Output is correct
10 Incorrect 10 ms 82512 KB Output isn't correct
11 Halted 0 ms 0 KB -