Submission #419431

# Submission time Handle Problem Language Result Execution time Memory
419431 2021-06-07T06:04:47 Z tengiz05 Watching (JOI13_watching) C++17
100 / 100
816 ms 15300 KB
#include <bits/stdc++.h>
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, p, q;
    std::cin >> n >> p >> q;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    if (p + q >= n) {
        std::cout << 1 << "\n";
        return 0;
    }
    sort(a.begin(), a.end());
    auto check = [&](int len) {
        std::vector<std::vector<int>> dp(n + 1, std::vector<int>(q + 1, 1e9));
        dp[0][0] = 0;
        int p1 = 1, p2 = 1;
        for (int i = 1; i <= n; i++) {
            while (a[i - 1] - a[p1 - 1] >= len) p1++;
            while (a[i - 1] - a[p2 - 1] >= 2 * len) p2++;
            for (int Q = 0; Q <= q; Q++) {
                dp[i][Q] = std::min(dp[i][Q], dp[p1 - 1][Q] + 1);
                if (Q) {
                    dp[i][Q] = std::min(dp[i][Q], dp[i][Q - 1]);
                    dp[i][Q] = std::min(dp[i][Q], dp[p2 - 1][Q - 1]);
                }
            }
        }
        return dp[n][q] <= p;
    };
    // for (int i = 1; i <= 17; i++) std::cerr << check(i) << "\n";
    // return 0;
    int l = 0, r = 1000000007;
    while (l + 1 < r) {
        int mid = (l + r) / 2;
        if (check(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    std::cout << r << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 368 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 8 ms 464 KB Output is correct
8 Correct 317 ms 6324 KB Output is correct
9 Correct 52 ms 1476 KB Output is correct
10 Correct 38 ms 1152 KB Output is correct
11 Correct 816 ms 15300 KB Output is correct
12 Correct 423 ms 8208 KB Output is correct
13 Correct 9 ms 460 KB Output is correct
14 Correct 7 ms 460 KB Output is correct
15 Correct 9 ms 540 KB Output is correct