Submission #155535

# Submission time Handle Problem Language Result Execution time Memory
155535 2019-09-29T01:59:46 Z Learner99 K blocks (IZhO14_blocks) C++14
0 / 100
205 ms 71032 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define N 100006
int inf =10000000000006;

int dp[N][101];
int ind[N][101];
int pre[N];

int32_t main()
{
    int n, k;
    cin>>n>>k;

    vector < int > a(n+1);
    for(int i=1;i<=n;i++)
        cin>>a[i];

    a[0] = inf;

    
    

    int cur = 1;
    for(int i=1;i<=n;i++)
    {
        if( a[cur] < a[i])
                cur = i;
        dp[i][1] = a[cur];
        ind[i][1] = cur;
    }

    for(int j=2;j<=k;j++)
    {
        stack < int > s;
        for(int i=j;i<=n;i++)
        {
            dp[i][j] = dp[i-1][j-1] + a[i];
            ind[i][j] = i;

            while(s.size())
            {
                int temp = s.top();
                if( a[temp] < a[i] )
                {
                if(dp[temp][j] - a[ind[temp][j]] + a[i] < dp[i][j])
                {
                dp[i][j] = dp[temp][j] - a[ind[temp][j]] + a[i];
                }
                    s.pop();
                }
                else
                {
                    break;
                }
            }


            if(s.size())
            {
                int cur = s.top();
                if( dp[i][j] > dp[cur][j])
                {
                    dp[i][j] = dp[cur][j];
                    ind[i][j] = ind[cur][j];
                }
            }
            s.push(i);
        }
    }

    cout<<dp[n][k]<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 276 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Incorrect 2 ms 504 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 16248 KB Output is correct
2 Correct 77 ms 70904 KB Output is correct
3 Correct 100 ms 71000 KB Output is correct
4 Incorrect 205 ms 71032 KB Output isn't correct
5 Halted 0 ms 0 KB -