Submission #688584

# Submission time Handle Problem Language Result Execution time Memory
688584 2023-01-27T18:50:01 Z four_specks Watching (JOI13_watching) C++17
50 / 100
1000 ms 12356 KB
#include <bits/stdc++.h>

using namespace std;

namespace
{
} // namespace

void solve()
{
    int n, p, q;
    cin >> n >> p >> q;

    p = min(p, n),
    q = min(q, n);

    vector<long> a(n);
    for (long &x : a)
        cin >> x;
    sort(a.begin(), a.end());

    auto pos = [&](long x)
    { return lower_bound(a.begin(), a.end(), x) - a.begin(); };

    auto check = [&](long mid) -> bool
    {
        vector dp(n + 1, vector<int>(p + 1, INT_MAX));
        for (int i = 0; i <= p; i++)
            dp[0][i] = 0;
        for (int i = 0; i < n; i++)
        {
            dp[i + 1][0] = dp[pos(a[i] - 2 * mid + 1)][0] + 1;
            for (int j = 0; j < p; j++)
                dp[i + 1][j + 1] = min(dp[pos(a[i] - mid + 1)][j], dp[pos(a[i] - 2 * mid + 1)][j + 1] + 1);
        }

        return dp[n][p] <= q;
    };

    long lo = 1, hi = 1'000'000'000;
    while (lo < hi)
    {
        long mid = (lo + hi) / 2;
        if (check(mid))
            hi = mid;
        else
            lo = mid + 1;
    }

    cout << hi << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 6 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 6 ms 368 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 2 ms 332 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 1 ms 320 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 7 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 1089 ms 12356 KB Time limit exceeded
4 Halted 0 ms 0 KB -