Submission #90644

# Submission time Handle Problem Language Result Execution time Memory
90644 2018-12-23T08:39:33 Z popovicirobert K blocks (IZhO14_blocks) C++14
0 / 100
3 ms 964 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int INF = 1e9;
const int MAXN = 100;

int dp[MAXN + 1][MAXN + 1];
int arr[MAXN + 1];

int stk[MAXN + 1];
int mx[MAXN + 1];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, n, k;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    for(i = 1; i <= n; i++) {
        dp[i][1] = max(dp[i - 1][1], arr[i]);
    }
    for(j = 2; j <= k; j++) {
        int sz = 0;
        dp[0][j] = mx[0] = INF;
        for(i = 1; i <= n; i++) {
            while(sz > 0 && arr[i] >= arr[stk[sz]]) {
                sz--;
            }
            stk[++sz] = i;
            mx[sz] = min(mx[sz - 1], arr[i] + dp[stk[sz - 1] + 1][j - 1]);
            dp[i][j] = mx[sz];
        }
    }
    cout << dp[n][k];
    //cin.close();
    //cout.close();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 472 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 720 KB Output is correct
9 Correct 2 ms 736 KB Output is correct
10 Incorrect 2 ms 736 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 736 KB Output is correct
2 Correct 2 ms 736 KB Output is correct
3 Correct 2 ms 736 KB Output is correct
4 Correct 2 ms 772 KB Output is correct
5 Correct 2 ms 772 KB Output is correct
6 Correct 2 ms 772 KB Output is correct
7 Correct 2 ms 772 KB Output is correct
8 Correct 2 ms 772 KB Output is correct
9 Correct 2 ms 772 KB Output is correct
10 Incorrect 2 ms 772 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 964 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -