답안 #968626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968626 2024-04-23T18:39:30 Z vjudge1 구경하기 (JOI13_watching) C++17
100 / 100
192 ms 16424 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 2000;
const int MAXA = 1e9;
const int INF = 1e9;

int N, P, Q;
int A[MAXN + 5];
int nextP[MAXN + 5], nextQ[MAXN + 5];
int DP[MAXN + 5][MAXN + 5];

int f(int idx, int p) {
    if (p < 0) return INF;
    if (idx == N) return 0;
    int &ret = DP[idx][p];
    if (ret != -1) return ret;
    return ret = min(f(nextP[idx], p - 1), f(nextQ[idx], p) + 1);
}

bool valid(int w) {
    for (int i = 0; i < N; i++) {
        nextP[i] = nextQ[i] = N;
        for (int j = i + 1; j < N; j++) {
            if (A[j] - A[i] + 1 > w) {
                nextP[i] = j;
                break;
            }
        }
        for (int j = i + 1; j < N; j++) {
            if (A[j] - A[i] + 1 > 2 * w) {
                nextQ[i] = j;
                break;
            }
        }
    }
    memset(DP, -1, sizeof DP);
    return f(0, P) <= Q;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> N >> P >> Q;
    for (int i = 0; i < N; i++) cin >> A[i];
    if (P + Q >= N) {
        cout << 1 << endl;
        return 0;
    }
    sort(A, A + N);
    int l = 1, r = MAXA, ans = INF, mid;
    while (l <= r) {
        mid = (l + r) / 2;
        if (valid(mid)) {
            ans = min(ans, mid);
            r = mid - 1;
        }
        else l = mid + 1;
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 16372 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 23 ms 16076 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 Correct 25 ms 15964 KB Output is correct
8 Correct 22 ms 15964 KB Output is correct
9 Correct 23 ms 15960 KB Output is correct
10 Correct 21 ms 15964 KB Output is correct
11 Correct 22 ms 15964 KB Output is correct
12 Correct 26 ms 15964 KB Output is correct
13 Correct 29 ms 15964 KB Output is correct
14 Correct 25 ms 15964 KB Output is correct
15 Correct 26 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 16220 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 36 ms 16060 KB Output is correct
8 Correct 45 ms 16248 KB Output is correct
9 Correct 86 ms 16220 KB Output is correct
10 Correct 192 ms 16264 KB Output is correct
11 Correct 45 ms 16424 KB Output is correct
12 Correct 162 ms 16300 KB Output is correct
13 Correct 45 ms 16212 KB Output is correct
14 Correct 33 ms 16220 KB Output is correct
15 Correct 31 ms 16240 KB Output is correct