답안 #972982

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972982 2024-05-01T11:19:26 Z bonk 구경하기 (JOI13_watching) C++17
100 / 100
235 ms 16296 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 15960 KB Output is correct
2 Correct 22 ms 15964 KB Output is correct
3 Correct 33 ms 16192 KB Output is correct
4 Correct 33 ms 15964 KB Output is correct
5 Correct 23 ms 15960 KB Output is correct
6 Correct 24 ms 15964 KB Output is correct
7 Correct 22 ms 15992 KB Output is correct
8 Correct 29 ms 15964 KB Output is correct
9 Correct 29 ms 15960 KB Output is correct
10 Correct 24 ms 15960 KB Output is correct
11 Correct 21 ms 15964 KB Output is correct
12 Correct 23 ms 15964 KB Output is correct
13 Correct 26 ms 16120 KB Output is correct
14 Correct 23 ms 15960 KB Output is correct
15 Correct 24 ms 15968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 15964 KB Output is correct
2 Correct 26 ms 16004 KB Output is correct
3 Correct 192 ms 16280 KB Output is correct
4 Correct 53 ms 16296 KB Output is correct
5 Correct 192 ms 16280 KB Output is correct
6 Correct 184 ms 16256 KB Output is correct
7 Correct 29 ms 15964 KB Output is correct
8 Correct 89 ms 16220 KB Output is correct
9 Correct 51 ms 16220 KB Output is correct
10 Correct 52 ms 16212 KB Output is correct
11 Correct 235 ms 16280 KB Output is correct
12 Correct 160 ms 16216 KB Output is correct
13 Correct 32 ms 15976 KB Output is correct
14 Correct 31 ms 15972 KB Output is correct
15 Correct 24 ms 16204 KB Output is correct