Submission #329810

# Submission time Handle Problem Language Result Execution time Memory
329810 2020-11-22T15:52:22 Z Vladth11 Stove (JOI18_stove) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;

const ll NMAX = 100001;
const ll INF = (1 << 16) - 1;
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 20;

int dp[2][NMAX];

int main() {
    //ifstream cin("multigraph.in");
    //ofstream cout("multigraph.out");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, i, j, last = 0, maxim = 2e9, k;
    cin >> n >> k;
    for(i = 0; i <= k; i++)
        dp[0][i] = dp[1][i] = 2e9;
    for(i = 1; i <= n; i++){
        int x;
        cin >> x;
        if(i == 1){
            dp[1][1] = 1;
        }else{
            for(j = 1; j <= k; j++){
                dp[i % 2][j] = dp[(i - 1) % 2][j] + (x - last);
                dp[i % 2][j] = min(dp[(i - 1) % 2][j - 1] + 1, dp[i % 2][j]);
                if(i == n)
                maxim = min(maxim, dp[i % 2][j]);
            }
        }
        last = x;
    }
    cout << maxim;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 376 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 376 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 376 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