Submission #601343

# Submission time Handle Problem Language Result Execution time Memory
601343 2022-07-21T18:04:20 Z elkernos Watching (JOI13_watching) C++17
100 / 100
344 ms 15440 KB
#include <bits/stdc++.h>

using namespace std;

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n, p, q;
    cin >> n >> p >> q;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    sort(1 + a.begin(), a.end());
    auto good = [&](int x) {
        int one = 1, two = 1;
        vector<vector<int>> dp(n + 1, vector<int>(q + 1));
        for(int i = 1; i <= n; ++i) {
            while(a[i] - a[one] >= x) {
                ++one;
            }
            while(a[i] - a[two] >= x * 2) {
                ++two;
            }
            for(int j = 0; j <= q; ++j) {
                dp[i][j] = dp[one - 1][j] + 1;
            }
            for(int j = 0; j < q; ++j) {
                if(dp[i][j + 1] > dp[two - 1][j]) {
                    dp[i][j + 1] = dp[two - 1][j];
                }
            }
        }
        return (dp[n][q] <= p);
    };
    if(n <= p + q) {
        cout << 1 << '\n';
        exit(0);
    }
    int l = 1, r = 1000000000, ans = -1;
    while(l <= r) {
        int m = (l + r) / 2;
        if(good(m)) {
            r = m - 1;
            ans = m;
        }
        else {
            l = m + 1;
        }
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 136 ms 6372 KB Output is correct
9 Correct 25 ms 1484 KB Output is correct
10 Correct 17 ms 1104 KB Output is correct
11 Correct 344 ms 15440 KB Output is correct
12 Correct 169 ms 8184 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 7 ms 468 KB Output is correct