Submission #249933

# Submission time Handle Problem Language Result Execution time Memory
249933 2020-07-16T13:48:50 Z apostoldaniel854 K blocks (IZhO14_blocks) C++14
0 / 100
6 ms 1536 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

const int N = 1e5, K = 100;
int a[1 + N];
int dp[1 + K][1 + N];
int mn[1 + N];
int stk[1 + N];

int main() {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);

    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        dp[1][i] = max (dp[1][i - 1], a[i]);
    }
    dp[1][0] = (1 << 30);
    for (int nrBlocks = 2; nrBlocks <= k; nrBlocks++) {
        int vf = 0;
        for (int i = 1; i <= n; i++) {
            int best = dp[nrBlocks - 1][i - 1];
            while (vf && a[stk[vf]] <= a[i]) {
                best = min (best, mn[stk[vf]]);
                vf--;
            }
            mn[i] = best;
            dp[nrBlocks][i] = a[i] + best;
            if (vf)
                dp[nrBlocks][i] = min (dp[nrBlocks][i], dp[nrBlocks][stk[vf]]);
            stk[++vf] = i;
        }
    }
    cout << dp[k][n] << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 384 KB Output is correct
5 Correct 0 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 Incorrect 0 ms 384 KB Output isn't correct
10 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 0 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 Incorrect 0 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -