Submission #140778

# Submission time Handle Problem Language Result Execution time Memory
140778 2019-08-05T03:04:26 Z ndhuy K blocks (IZhO14_blocks) C++14
0 / 100
10 ms 2680 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int n, k;
int64 a[100005];
int64 f[105][100005];
stack <int> st;
stack <int64> mx;

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    a[0] = 1e9;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= k; j++)
            f[j][i] = 1e12;
    f[0][0] = 0;
    for (int j = 1; j <= k; j++){
        while (!st.empty()) st.pop(), mx.pop();
        a[j - 1] = 1e12;
        st.push(j - 1);
        mx.push(1e12);
        for (int i = j; i <= n; i++){
            while (st.size() && a[i] >= a[st.top()]){
                st.pop();
                mx.pop();
            }
            mx.push(min(mx.top(), f[j - 1][st.top()] + a[i]));
            st.push(i);
            f[j][i] = mx.top();
        }
        int64 tmp = f[j][n];
        for (int i = n - 1; i >= 1; i--){
            tmp = min(tmp, f[j][i]);
            f[j][i] = tmp;
        }
        //for (int i = 1; i <= n; i++) cout << f[j][i] << ' '; cout << endl;
    }
    cout << f[k][n];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -