Submission #471334

# Submission time Handle Problem Language Result Execution time Memory
471334 2021-09-08T13:08:01 Z Newtech66 K blocks (IZhO14_blocks) C++17
0 / 100
1 ms 316 KB
#include<bits/stdc++.h>
using namespace std;
using lol=long long int;
#define endl "\n"
const lol mod1=1e9+7,mod2=998244353;
const lol inf=1e12+8;
const double eps=1e-12;
const int N=1e5+5;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int _=1;
//cin>>_;
while(_--)
{
    int n,k;
    cin>>n>>k;
    vector<lol> v(n);
    for(auto& e:v)  cin>>e;
    vector<int> pg(n);
    stack<int> st;
    for(int i=0;i<n;i++)
    {
        while(!st.empty() && v[st.top()]<v[i]) st.pop();
        if(st.empty())  pg[i]=-1;
        else    pg[i]=st.top();
        st.push(i);
    }
    lol dp[n][k];
    lol mn[k];
    lol curmx=v[0];
    dp[0][0]=curmx;
    mn[0]=v[0];
    for(int j=1;j<k;j++)    dp[0][j]=inf,mn[j]=inf;
    for(int i=1;i<n;i++)
    {
        curmx=max(curmx,v[i]);
        dp[i][0]=curmx;
        for(int j=1;j<k;j++)
        {
            if(pg[i]!=-1)   dp[i][j]=min(dp[pg[i]][j-1]+v[i],dp[pg[i]][j]);
            else   dp[i][j]=min(dp[i][j],mn[j-1]+v[i]);
            dp[i][j]=min(inf,dp[i][j]);
        }
        for(int j=0;j<k;j++)    mn[j]=min(mn[j],dp[i][j]);
    }
    cout<<dp[n-1][k-1];
}
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Incorrect 1 ms 204 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Incorrect 1 ms 204 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Incorrect 1 ms 204 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Incorrect 1 ms 204 KB Output isn't correct
12 Halted 0 ms 0 KB -