Submission #601016

# Submission time Handle Problem Language Result Execution time Memory
601016 2022-07-21T10:09:24 Z pakhomovee Stove (JOI18_stove) C++17
0 / 100
5 ms 1884 KB
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define int long long
const int maxn = 100'001;
const int inf = 1e18;
int dp[maxn];
int p[maxn];

pair<int, int> eval(int lambda, vector<int> &t) {
    const int n = t.size();
    fill(dp, dp + maxn, inf);
    fill(p, p + maxn, -1);
    dp[0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i; j > 0; --j) {
            dp[i] = min(dp[i], dp[j - 1] + t[i - 1] - t[j - 1] + 1 + lambda);
            if (dp[i] == dp[j - 1] + t[i - 1] - t[j - 1] + 1 + lambda) {
                p[i] = j - 1;
            }
        }
    }
    int ptr = n;
    int cnt = 0;
    while (ptr != 0) {
        ++cnt;
        ptr = p[ptr];
    }
    return { dp[n], cnt };
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> t(n);
    for (int& i : t) {
        cin >> i;
    }
    int l = 0, r = 1e9;
    while (l + 1 < r) {
        int m = (l + r) / 2;
        if (eval(m, t).second > k) {
            l = m;
        } else {
            r = m;
        }
    }
    auto [a, b] = eval(r, t);
    cout << a - k * r;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1884 KB Output is correct
2 Correct 3 ms 1864 KB Output is correct
3 Correct 4 ms 1876 KB Output is correct
4 Correct 3 ms 1876 KB Output is correct
5 Incorrect 3 ms 1876 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1884 KB Output is correct
2 Correct 3 ms 1864 KB Output is correct
3 Correct 4 ms 1876 KB Output is correct
4 Correct 3 ms 1876 KB Output is correct
5 Incorrect 3 ms 1876 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1884 KB Output is correct
2 Correct 3 ms 1864 KB Output is correct
3 Correct 4 ms 1876 KB Output is correct
4 Correct 3 ms 1876 KB Output is correct
5 Incorrect 3 ms 1876 KB Output isn't correct
6 Halted 0 ms 0 KB -