Submission #845807

# Submission time Handle Problem Language Result Execution time Memory
845807 2023-09-06T15:56:54 Z BamshooT K blocks (IZhO14_blocks) C++14
0 / 100
7 ms 45144 KB
#include <iostream>
#include <cstring>
#include <vector>
#include <stack>

#define ll long long
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define fi first
#define se second
#define inf 1e9

using namespace std;

typedef pair <int, int> ii;

const int N = 1e5 + 9;
int n, k, a[N], dp[N][109], st[N << 2], L[N];

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   // freopen("nhap.inp", "r", stdin);
   // freopen("xuat.out", "w", stdout);
    cin >> n >> k;
    FOR(i, 1, n) cin >> a[i];
    memset(dp, 0x3f, sizeof dp);
    dp[1][1] = a[1];
    FOR(i, 2, n) dp[i][1] = max(dp[i-1][1], a[i]);
    for (int t = 2; t <= k; ++t){
        stack <ii> st;
        for (int i = t; i <= n; ++i) {
            int minF = dp[i-1][t-1];
            while (!st.empty() && a[st.top().se] <= a[i]){
                minF = min(minF, st.top().fi);
                st.pop();
            }
            dp[i][t] = (dp[i][st.empty() ? 0 : st.top().se], minF + a[i]);
            st.push({minF, i});
        }
    }
    cout << dp[n][k];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 5 ms 44892 KB Output is correct
3 Correct 5 ms 44788 KB Output is correct
4 Correct 6 ms 44892 KB Output is correct
5 Correct 6 ms 44756 KB Output is correct
6 Correct 6 ms 44796 KB Output is correct
7 Correct 6 ms 44836 KB Output is correct
8 Correct 6 ms 44892 KB Output is correct
9 Correct 5 ms 44888 KB Output is correct
10 Correct 6 ms 44836 KB Output is correct
11 Correct 7 ms 44892 KB Output is correct
12 Correct 5 ms 44888 KB Output is correct
13 Incorrect 5 ms 44892 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44892 KB Output is correct
2 Correct 6 ms 44892 KB Output is correct
3 Correct 5 ms 44892 KB Output is correct
4 Correct 6 ms 44788 KB Output is correct
5 Correct 6 ms 44892 KB Output is correct
6 Correct 5 ms 44892 KB Output is correct
7 Correct 6 ms 45144 KB Output is correct
8 Correct 5 ms 44892 KB Output is correct
9 Correct 5 ms 44892 KB Output is correct
10 Correct 6 ms 44892 KB Output is correct
11 Correct 6 ms 44812 KB Output is correct
12 Correct 6 ms 44892 KB Output is correct
13 Correct 5 ms 44892 KB Output is correct
14 Incorrect 6 ms 44788 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 5 ms 44892 KB Output is correct
3 Correct 5 ms 44788 KB Output is correct
4 Correct 6 ms 44892 KB Output is correct
5 Correct 6 ms 44756 KB Output is correct
6 Correct 6 ms 44796 KB Output is correct
7 Correct 6 ms 44836 KB Output is correct
8 Correct 6 ms 44892 KB Output is correct
9 Correct 5 ms 44888 KB Output is correct
10 Correct 6 ms 44836 KB Output is correct
11 Correct 7 ms 44892 KB Output is correct
12 Correct 5 ms 44888 KB Output is correct
13 Incorrect 5 ms 44892 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 44888 KB Output is correct
2 Correct 5 ms 44892 KB Output is correct
3 Correct 5 ms 44788 KB Output is correct
4 Correct 6 ms 44892 KB Output is correct
5 Correct 6 ms 44756 KB Output is correct
6 Correct 6 ms 44796 KB Output is correct
7 Correct 6 ms 44836 KB Output is correct
8 Correct 6 ms 44892 KB Output is correct
9 Correct 5 ms 44888 KB Output is correct
10 Correct 6 ms 44836 KB Output is correct
11 Correct 7 ms 44892 KB Output is correct
12 Correct 5 ms 44888 KB Output is correct
13 Incorrect 5 ms 44892 KB Output isn't correct
14 Halted 0 ms 0 KB -