답안 #601035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
601035 2022-07-21T10:19:03 Z pakhomovee Stove (JOI18_stove) C++17
50 / 100
1000 ms 3432 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 dp1[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);
    fill(dp1, dp1 + maxn, inf);
    dp[0] = 0;
    dp1[0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i; j > 0; --j) {
            if (dp[i] > dp[j - 1] + t[i - 1] - t[j - 1] + 1 + lambda) {
                dp1[i] = dp1[j - 1] + 1;
                dp[i] = dp[j - 1] + t[i - 1] - t[j - 1] + 1 + lambda;
            } else if (dp[i] == dp[j - 1] + t[i - 1] - t[j - 1] + 1 + lambda) {
                dp1[i] = min(dp1[i], dp1[j - 1] + 1);
            }
        }
    }
    return { dp[n], dp1[n] };
}

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 = -1, r = 2e9;
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 4 ms 2644 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 4 ms 2672 KB Output is correct
5 Correct 4 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 4 ms 2644 KB Output is correct
8 Correct 7 ms 2644 KB Output is correct
9 Correct 4 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 4 ms 2644 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 4 ms 2672 KB Output is correct
5 Correct 4 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 4 ms 2644 KB Output is correct
8 Correct 7 ms 2644 KB Output is correct
9 Correct 4 ms 2644 KB Output is correct
10 Correct 178 ms 2680 KB Output is correct
11 Correct 163 ms 2676 KB Output is correct
12 Correct 154 ms 2672 KB Output is correct
13 Correct 161 ms 2672 KB Output is correct
14 Correct 156 ms 2672 KB Output is correct
15 Correct 143 ms 2676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 4 ms 2644 KB Output is correct
3 Correct 4 ms 2644 KB Output is correct
4 Correct 4 ms 2672 KB Output is correct
5 Correct 4 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 4 ms 2644 KB Output is correct
8 Correct 7 ms 2644 KB Output is correct
9 Correct 4 ms 2644 KB Output is correct
10 Correct 178 ms 2680 KB Output is correct
11 Correct 163 ms 2676 KB Output is correct
12 Correct 154 ms 2672 KB Output is correct
13 Correct 161 ms 2672 KB Output is correct
14 Correct 156 ms 2672 KB Output is correct
15 Correct 143 ms 2676 KB Output is correct
16 Execution timed out 1089 ms 3432 KB Time limit exceeded
17 Halted 0 ms 0 KB -