Submission #285424

# Submission time Handle Problem Language Result Execution time Memory
285424 2020-08-28T22:52:02 Z loideptrai1 K blocks (IZhO14_blocks) C++14
0 / 100
7 ms 4512 KB
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define name ""
#define inout freopen(name".inp","r", stdin); freopen(name".out","w",stdout);

using namespace std;

const int N=1e5+5;
const int MOD=1e9+7;
const int base=257;
const int M=1e6+1;
const int INFI=1e9;

int a[N], dp[N][105];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //inout;
    //precomputecombinatorics();
    //precomputehashing();
    int n,k;
    cin >> n >> k;
    for (int i=1; i<=n; i++){
        cin >> a[i];
    }
    for (int i=0; i<=n; i++){
        for (int j=0; j<=k; j++){
            dp[i][j]=INFI;
        }
    }
    dp[0][0]=0;
    for (int j=1; j<=k; j++){
        deque <pii> d;
        d.clear();
        for (int i=j; i<=n; i++){
            int minv=dp[i-1][j-1];
            while (d.size() && a[d.back().first]<=a[i]){
                minv=min(minv,d.back().second);
                d.pop_back();
            }
            int pos=0;
            if (d.size()){
                pos=d.back().first;
            }
            dp[i][j]=min(dp[pos][j],minv+a[i]);
            //cout << i << " " << j << " " << dp[pos][j] << "\n";
            d.push_back(pii(j,minv));
        }
    }

    cout << dp[n][k];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Incorrect 0 ms 384 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Incorrect 0 ms 384 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4512 KB Output isn't correct
2 Halted 0 ms 0 KB -