답안 #367440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
367440 2021-02-17T10:57:54 Z vishesh312 구경하기 (JOI13_watching) C++17
100 / 100
446 ms 15544 KB
#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/

#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()

using ll = long long;
const int mod = 1e9+7;
int n, p, q;
vector<int> v;

bool chk(int w) {
    vector<vector<int>> dp(n, vector<int>(p+1));
    int smol = 0, big = 0;
    for (int i = 0; i < n; ++i) {
        while (v[i] - v[smol] >= w) ++smol;
        while (v[i] - v[big] >= 2*w) ++big;
        if (big) dp[i][0] = dp[big-1][0] + 1;
        else dp[i][0] = 1;
        for (int j = 1; j <= p; ++j) {
            if (smol == 0) dp[i][j] = 0;
            else if (big == 0) dp[i][j] = min(dp[smol-1][j-1], 1);
            else dp[i][j] = min(dp[smol-1][j-1], dp[big-1][j] + 1);
        }
    }
//  for (int i = 0; i <= p; ++i) cerr << dp[n-1][i] << " ";
//  cerr << '\n';
    return dp[n-1][p] <= q;
}

void solve(int tc) {
    cin >> n >> p >> q;
    v.resize(n);
    for (auto &x : v) cin >> x;
    sort(all(v));
    if (p+q >= n) {
        cout << "1\n";
        return;
    }
    int lo = 0, hi = 1e9+1;
    while (lo < hi) {
        int mid = lo + (hi - lo) / 2;
//      cerr << "mid : " << mid << '\n';
        if (chk(mid)) {
            hi = mid;
        } else {
            lo = mid+1;
        }
    }
    cout << hi << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int tc = 1;
    //cin >> tc;
    for (int i = 1; i <= tc; ++i) solve(i);
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 30 ms 1468 KB Output is correct
9 Correct 186 ms 6424 KB Output is correct
10 Correct 446 ms 15544 KB Output is correct
11 Correct 21 ms 1184 KB Output is correct
12 Correct 222 ms 8212 KB Output is correct
13 Correct 5 ms 492 KB Output is correct
14 Correct 6 ms 620 KB Output is correct
15 Correct 6 ms 620 KB Output is correct