Submission #883694

# Submission time Handle Problem Language Result Execution time Memory
883694 2023-12-05T18:06:50 Z alexdd K blocks (IZhO14_blocks) C++17
0 / 100
1 ms 2396 KB
#include<iostream>
#include<deque>
using namespace std;
const int INF = 1e9;
int n,k;
int a[100005];
int tole[100005];
int tori[100005];
int dp[100005][105];
signed main()
{
    cin>>n>>k;
    deque<int> dq;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        while(!dq.empty() && a[dq.back()]<=a[i])
            dq.pop_back();
        if(dq.empty())
            tole[i]=0;
        else
            tole[i]=dq.back();
        dq.push_back(i);
        for(int j=1;j<=k;j++)
            dp[i][j]=INF;
    }
    dq.clear();
    for(int i=n;i>0;i--)
    {
        while(!dq.empty() && a[dq.back()]<=a[i])
            dq.pop_back();
        if(dq.empty())
            tori[i]=n+1;
        else
            tori[i]=dq.back();
        dq.push_back(i);
    }
    for(int i=1;i<=k;i++)
        dp[0][i]=INF;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=0;
        for(int j=1;j<=k;j++)
        {
            if(dp[tole[i]][j-1]==INF)
                continue;
            //cout<<i<<" "<<j<<" zzz\n";
            dp[tori[i]-1][j] = min(dp[tori[i]-1][j], dp[tole[i]][j-1] + a[i]);
            for(int x=tori[i]-1;x>=0;x--)
                dp[x][j] = min(dp[x][j], dp[tole[i]][j-1] + a[i]);
        }
    }
    cout<<dp[n][k];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2392 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -