답안 #976770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976770 2024-05-07T05:49:23 Z vjudge1 구경하기 (JOI13_watching) C++17
0 / 100
1000 ms 604 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int n;
vector <ll> jalur;

bool cek(int p, int q, int k, ll last) {
    if (last>=n) return true;
    if (p==0&&q==0) return false;
    bool a=false, b=false;
    if (q>0) {
        ll jq=jalur[last]-1+(k*2);
        ll akhir = upper_bound(jalur.begin(), jalur.end(), jq) - jalur.begin();
        a = cek(p, q-1, k, akhir);
    }
    if (a) return true;
    if (p>0) {
        ll jp=jalur[last]-1+k;
        ll akhir = upper_bound(jalur.begin(), jalur.end(), jp) - jalur.begin();
        b = cek(p-1, q, k, akhir);
    }
    return a||b;
}

int main() {
    int p, q; cin >> n >> p >> q;
    for (int i=0;i<n;i++) {
        ll x; cin >> x;
        jalur.push_back(x);
    }
    sort(jalur.begin(), jalur.end());
    ll kiri=1, kanan = 1e9, mid, ans=1;
    while (kiri<=kanan) {
        mid = (kiri+kanan)/2;
        if (cek(p, q, mid, 0)) {
            ans = mid;
            kanan = mid-1;
        } else {
            kiri = mid+1;
        }
    }
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 500 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 6 ms 500 KB Output is correct
9 Correct 6 ms 432 KB Output is correct
10 Execution timed out 1095 ms 348 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Execution timed out 1086 ms 348 KB Time limit exceeded
8 Halted 0 ms 0 KB -