Submission #336602

# Submission time Handle Problem Language Result Execution time Memory
336602 2020-12-15T22:52:21 Z jovan_b K blocks (IZhO14_blocks) C++17
0 / 100
1 ms 492 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define pb push_back

int dp[2][100005];
int a[100005];
int pre[100005];

const int INF = 1000000000;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, k;
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=n; i++){
        dp[0][i] = max(dp[0][i-1], a[i]);
        pre[i] = pre[i-1] + a[i];
    }
    for(int g=2; g<=k; g++){
        deque <pair <pair <int, int>, pair <int, int>>> q;
        for(int i=1; i<g; i++){
            dp[1][i] = INF;
        }
        //dp[1][g] = pre[g];
        for(int i=g; i<=n; i++){
            int mnl = i-1;
            while(!q.empty() && q.back().second.first <= a[i]){
                mnl = min(mnl, q.back().first.first);
                q.pop_back();
            }
            //cout << i << " " << mnl << endl;
            dp[1][i] = dp[0][mnl] + a[i];
            if(!q.empty()) dp[1][i] = min(dp[1][i], q.back().second.second);
            q.push_back({{mnl, i-1}, {a[i], dp[1][i]}});
        }
        for(int i=0; i<=n; i++) dp[0][i] = min(INF, dp[1][i]);
    }
    cout << dp[0][n] << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 0 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 0 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 0 ms 364 KB Output isn't correct
10 Halted 0 ms 0 KB -