Submission #31752

# Submission time Handle Problem Language Result Execution time Memory
31752 2017-09-06T03:45:32 Z aome K blocks (IZhO14_blocks) C++14
0 / 100
9 ms 13892 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;
const int N = 1000005;
const int INF = 1e9;

int n, k, f[2][N], a[N];

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) f[0][i] = INF;
    for (int i = 1; i <= k; ++i) {
        bool t = i & 1;
        stack<ii> st[2];
        f[t][0] = INF;
        for (int j = 1; j <= n; ++j) {
            int pos = j;
            int val = f[t ^ 1][j - 1];
            while (st[0].size() && a[st[0].top().first] <= a[j]) {
                pos = st[0].top().first;
                val = min(val, st[0].top().second);
                st[0].pop(); continue;
            }
            st[0].push(ii(pos, val));
            while (st[1].size() && st[1].top().first >= pos) st[1].pop();
            if (!(st[1].size() && st[1].top().second <= val + a[j])) {
                st[1].push(ii(pos, val + a[j]));
            }
            f[t][j] = st[1].top().second;
            //cout << pos << ' ' << val << ' ' << f[t][j] << ' ' << j << '\n';
        }
    }
    cout << f[k & 1][n];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13892 KB Output is correct
2 Correct 0 ms 13892 KB Output is correct
3 Correct 0 ms 13892 KB Output is correct
4 Correct 0 ms 13892 KB Output is correct
5 Correct 0 ms 13892 KB Output is correct
6 Correct 0 ms 13892 KB Output is correct
7 Correct 0 ms 13892 KB Output is correct
8 Correct 0 ms 13892 KB Output is correct
9 Correct 0 ms 13892 KB Output is correct
10 Correct 0 ms 13892 KB Output is correct
11 Correct 0 ms 13892 KB Output is correct
12 Incorrect 0 ms 13892 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13892 KB Output is correct
2 Correct 0 ms 13892 KB Output is correct
3 Correct 0 ms 13892 KB Output is correct
4 Correct 0 ms 13892 KB Output is correct
5 Correct 0 ms 13892 KB Output is correct
6 Correct 0 ms 13892 KB Output is correct
7 Correct 0 ms 13892 KB Output is correct
8 Correct 0 ms 13892 KB Output is correct
9 Correct 0 ms 13892 KB Output is correct
10 Correct 0 ms 13892 KB Output is correct
11 Correct 0 ms 13892 KB Output is correct
12 Correct 0 ms 13892 KB Output is correct
13 Correct 0 ms 13892 KB Output is correct
14 Incorrect 0 ms 13892 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 13892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 13892 KB Output isn't correct
2 Halted 0 ms 0 KB -