답안 #966391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966391 2024-04-19T19:13:55 Z oviyan_gandhi 구경하기 (JOI13_watching) C++17
0 / 100
5 ms 2652 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;
    }
    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;
}
# 결과 실행 시간 메모리 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 1 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 Incorrect 0 ms 464 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 472 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Incorrect 5 ms 2652 KB Output isn't correct
9 Halted 0 ms 0 KB -