답안 #503112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503112 2022-01-07T09:37:49 Z colossal_pepe 구경하기 (JOI13_watching) C++17
50 / 100
1000 ms 15544 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int n, p, q;
vector<int> v;
 
int brutus(int w, int i, int p_left, vector<vector<int>> &dp) {
    if (i >= n) return 0;
    if (dp[i][p_left] != -1) return dp[i][p_left];
    int useq = lower_bound(v.begin(), v.end(), v[i] + (2 * w)) - v.begin();
    dp[i][p_left] = brutus(w, useq, p_left, dp) + 1;
    if (p_left) {
        int usep = lower_bound(v.begin(), v.end(), v[i] + w) - v.begin();
        dp[i][p_left] = min(dp[i][p_left], brutus(w, usep, p_left - 1, dp));
    }
    return dp[i][p_left];
}
 
void reset(vector<vector<int>> &dp) {
    for (vector<int> &row : dp) {
        fill(row.begin(), row.end(), -1);
    }
}
 
int solve() {
    vector<vector<int>> dp(n, vector<int>(p + 1, -1));
    int minw = 1, maxw = 1e9;
    while (maxw - minw >= 5) {
        int mid = (maxw + minw) / 2;
        reset(dp);
        if (brutus(mid, 0, p, dp) <= q) maxw = mid;
        else minw = mid + 1;
    }
    for (int i = minw; i <= maxw; i++) {
        reset(dp);
        if (brutus(i, 0, p, dp) <= q) return i;
    }
    return 1e9;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> p >> q;
    v.resize(n);
    for (int &i : v) {
        cin >> i;
    }
    if (p + q >= n) {
        cout << 1 << endl;
        return 0;
    }
    sort(v.begin(), v.end());
    cout << solve() << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 4 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 3 ms 448 KB Output is correct
8 Correct 141 ms 1356 KB Output is correct
9 Correct 808 ms 6376 KB Output is correct
10 Execution timed out 1073 ms 15544 KB Time limit exceeded
11 Halted 0 ms 0 KB -