Submission #587622

# Submission time Handle Problem Language Result Execution time Memory
587622 2022-07-02T07:14:06 Z shrimb Stove (JOI18_stove) C++17
0 / 100
1 ms 212 KB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")

#include"bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991

// joi 2018 alien's trick attempt

int n, k;

int a[100001], pen;

pair<int,int> calc () {
    pair<int,int> dp[n];
    dp[0] = {0, 1};
    for (int i = 1 ; i < n ; i++) {
        pair<int,int> A = {dp[i-1].first + abs(a[i] - a[i-1]), dp[i-1].second};
        pair<int,int> B = {dp[i-1].first + pen, dp[i-1].second + 1};
        dp[i] = min(A, B);
    }
    return dp[n-1];
}

signed main () {
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> k;
    for (int i = 0 ; i < n ; i++) cin >> a[i];

    int l = 0, r = 1e9;
    while (r - l > 1) {
        // cerr << l << " " << r << endl;
        int m = pen = (l + r) / 2;
        int K = calc().second;
        if (K <= k) r = m;
        else l = m;
    }
    pen = r;
    cout << calc().first;
}

Compilation message

stove.cpp:17:1: warning: multi-line comment [-Wcomment]
   17 | //\
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -