Submission #966394

# Submission time Handle Problem Language Result Execution time Memory
966394 2024-04-19T19:15:55 Z oviyan_gandhi Watching (JOI13_watching) C++14
0 / 100
8 ms 2648 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

#define N 2001
int n, p, q, a[N], dp[N][N], nw[N], nw2[N]; // next w, next 2w

bool check(int w){
    for (int i = 1; i < n; i++){
        nw[i] = lower_bound(a+i, a+n+1, a[i] + w) - a - 1;
        nw2[i] = lower_bound(a+i, a+n+1, a[i] + 2*w) - a - 1;
    }
    nw[0] = nw[1];
    nw2[0] = nw2[1];
    for (int i = 0; i <= p; i++){
        for (int j = 0; j <= q; j++){
            dp[i][j] = 0;
            if (i)
                dp[i][j] = max(dp[i][j], nw[dp[i-1][j]+1]);
            if (j)
                dp[i][j] = max(dp[i][j], nw2[dp[i][j-1]+1]);
            if (dp[i][j] == n)
                return true;
        }
    }
    return false;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> p >> q;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    if ((p + q) >= n){
        cout << "1\n";
        return 0;
    }
    sort(a+1, a+n+1);
    int l = 0, r = 1e9, ans = r;
    while (l <= r){
        int mid = (l+r)/2;
        if (check(mid))
            ans = mid, r = mid-1;
        else l = mid+1;
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 5 ms 2392 KB Output is correct
8 Incorrect 8 ms 2648 KB Output isn't correct
9 Halted 0 ms 0 KB -