답안 #901308

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
901308 2024-01-09T10:13:55 Z KienTran 구경하기 (JOI13_watching) C++14
100 / 100
188 ms 15968 KB
#include <bits/stdc++.h>

using namespace std;

const int O = 2e3 + 5;
const int base = 500;
const int mod = 998244353;

int n, p, q, a[O], f[O][O];

bool check(int mid){
    f[0][0] = 0;
    int x = 0, y = 0;
    for (int i = 1; i <= n; ++ i){
        for (int j = 0; j <= min(i, q); ++ j){
            f[i][j] = 1e9;
            while (x < i && a[x + 1] < a[i] - 2 * mid + 1) x += 1;
            if (j) f[i][j] = min(f[i][j], f[x][j - 1]);

            while (y < i && a[y + 1] < a[i] - mid + 1) y += 1;
            f[i][j] = min(f[i][j], f[y][j] + 1);
        }
    }

    return f[n][q] <= p;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> p >> q;
    for (int i = 1; i <= n; ++ i) cin >> a[i];

    sort(a + 1, a + n + 1);
    //for (int i = 1; i <= n; ++ i) cout << a[i] << " "; cout << endl;

    if (p + q >= n) return cout << 1, 0;

    int l = 0, r = 1e9;
    while (l <= r){
        int mid = (l + r) / 2;
        if (check(mid)) r = mid - 1;
        else l = mid + 1;
    }

    cout << l;
}

Compilation message

watching.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 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 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 15452 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 6 ms 15452 KB Output is correct
8 Correct 131 ms 15928 KB Output is correct
9 Correct 27 ms 15556 KB Output is correct
10 Correct 20 ms 15704 KB Output is correct
11 Correct 188 ms 15964 KB Output is correct
12 Correct 140 ms 15968 KB Output is correct
13 Correct 6 ms 15448 KB Output is correct
14 Correct 5 ms 15452 KB Output is correct
15 Correct 6 ms 15320 KB Output is correct