제출 #1033284

#제출 시각아이디문제언어결과실행 시간메모리
1033284adaawfWatching (JOI13_watching)C++17
100 / 100
153 ms15964 KiB
#include <iostream>
#include <algorithm>
using namespace std;
int n, p, q, a[2005], f[2005][2005];
bool check(int x) {
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= p; j++) {
            f[i][j] = 1e9;
        }
    }
    for (int i = 1; i <= n; i++) {
        int h = upper_bound(a + 1, a + n + 1, a[i] - x) - a, k = upper_bound(a + 1, a + n + 1, a[i] - x * 2) - a;
        //cout << h << " " << k << " " << x << " " << i << '\n';
        for (int j = 0; j <= p; j++) {
            if (j != 0) f[i][j] = min(f[i][j], f[h - 1][j - 1]);
            f[i][j] = min(f[i][j], f[k - 1][j] + 1);
            //cout << i << " " << j << " " << f[i][j] << '\n';
        }
    }
    for (int j = 0; j <= p; j++) {
        if (f[n][j] <= q) return true;
    }
    return false;
}
int main() {
    ios::sync_with_stdio(0);
    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);
    if (p + q >= n) {
        cout << 1;
        return 0;
    }
    int l = 1, r = 1e9, res;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check(mid) == true) {
            res = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    cout << res;
}

컴파일 시 표준 에러 (stderr) 메시지

watching.cpp: In function 'int main()':
watching.cpp:46:13: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |     cout << res;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...