답안 #966399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966399 2024-04-19T19:27:11 Z oviyan_gandhi 구경하기 (JOI13_watching) C++14
100 / 100
52 ms 31312 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, j = 1, k = 1; i <= n; i++){
        while (j < n && a[j+1] - a[i] < w)
            j++;
        while (k < n && a[k+1] - a[i] < 2*w)
            k++;
        nw[i] = j;
        nw2[i] = k;
    }
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 420 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 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 Correct 1 ms 2396 KB Output is correct
8 Correct 8 ms 2652 KB Output is correct
9 Correct 10 ms 12892 KB Output is correct
10 Correct 21 ms 31312 KB Output is correct
11 Correct 6 ms 2904 KB Output is correct
12 Correct 52 ms 17524 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2528 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct