Submission #972979

# Submission time Handle Problem Language Result Execution time Memory
972979 2024-05-01T11:09:18 Z vjudge1 Watching (JOI13_watching) C++17
100 / 100
210 ms 16300 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int INF = 1e8;
const int MAX_N = 2005;
int dp[MAX_N][MAX_N], a[MAX_N], nxtP[MAX_N], nxtQ[MAX_N];
int N, P, Q;

int f(int idx, int remQ){
    if(remQ < 0) return INF;
    if(idx > N) return 0;
    auto &cur = dp[idx][remQ];

    if(cur != -1) return cur;

    cur = min(f(nxtP[idx], remQ) + 1, f(nxtQ[idx], remQ - 1));
    return cur;
}

bool check(int x){
    int j = 2, k = 2;
    for(int i = 1; i <= N; i++){
        while(j <= N && a[j] - a[i] + 1 <= x) j++;
        while(k <= N && a[k] - a[i] + 1 <= 2*x) k++;
        nxtP[i] = j;
        nxtQ[i] = k;
    }

    memset(dp, -1, sizeof(dp));
    return (f(1, Q) <= P);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> P >> Q;
    P = min(P, N); Q = min(Q, N);

    for(int i = 1; i <= N; i++) cin >> a[i];
    sort(a + 1, a + N + 1);

    ll ans = -1, l = 1, r = 1e9;

    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 26 ms 16080 KB Output is correct
2 Correct 27 ms 15964 KB Output is correct
3 Correct 29 ms 16200 KB Output is correct
4 Correct 24 ms 15964 KB Output is correct
5 Correct 25 ms 15964 KB Output is correct
6 Correct 24 ms 15964 KB Output is correct
7 Correct 30 ms 16204 KB Output is correct
8 Correct 26 ms 15964 KB Output is correct
9 Correct 24 ms 15964 KB Output is correct
10 Correct 22 ms 15960 KB Output is correct
11 Correct 24 ms 15964 KB Output is correct
12 Correct 31 ms 15964 KB Output is correct
13 Correct 29 ms 15964 KB Output is correct
14 Correct 30 ms 16204 KB Output is correct
15 Correct 26 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 16232 KB Output is correct
2 Correct 30 ms 16192 KB Output is correct
3 Correct 190 ms 16296 KB Output is correct
4 Correct 42 ms 16272 KB Output is correct
5 Correct 188 ms 16300 KB Output is correct
6 Correct 210 ms 16220 KB Output is correct
7 Correct 35 ms 16220 KB Output is correct
8 Correct 81 ms 16264 KB Output is correct
9 Correct 44 ms 16220 KB Output is correct
10 Correct 49 ms 16216 KB Output is correct
11 Correct 210 ms 16276 KB Output is correct
12 Correct 186 ms 16300 KB Output is correct
13 Correct 30 ms 16216 KB Output is correct
14 Correct 26 ms 16220 KB Output is correct
15 Correct 29 ms 16216 KB Output is correct