Submission #1306988

#TimeUsernameProblemLanguageResultExecution timeMemory
1306988ballbreaker구경하기 (JOI13_watching)C++20
100 / 100
543 ms31964 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, p, s;
    cin >> n >> p >> s;
    int a[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    p = min(p, n);
    s = min(s, n);
    int l = 1, r = INT_MAX;
    while (l < r) {
        int mid = (l + r) >> 1;
        int nxt[n + 2] = {};
        int pp = 0;
        for (int i = 1; i <= n; i++) {
            pp = max(pp, i);
            while (pp + 1 <= n && a[pp + 1] - a[i] + 1 <= mid) {
                pp++;
            }
            nxt[i] = pp;
            // cout << i << ' ' << p << endl;
        }
        nxt[n + 1] = n;
        int nxt2[n + 2] = {};
        pp = 0;
        for (int i = 1; i <= n; i++) {
            pp = max(pp, i);
            while (pp + 1 <= n && a[pp + 1] - a[i] + 1 <= 2 * mid) {
                pp++;
            }
            nxt2[i] = pp;
            // cout << i << ' ' << p << endl;
        }
        nxt2[n + 1] = n;
        int dp[p + 1][s + 1] = {};
        // cout << mid << '\n';
        for (int i = 0; i <= p; i++) {
            for (int j = 0; j <= s; j++) {
                if (i) {
                    dp[i][j] = max(dp[i][j], nxt[dp[i - 1][j] + 1]);
                }
                if (j) {
                    dp[i][j] = max(dp[i][j], nxt2[dp[i][j - 1] + 1]);
                }
                // cout << dp[i][j] << ' ';
            }
            // cout << endl;
        }
        if (dp[p][s] == n) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l;
}

Compilation message (stderr)

watching.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...