제출 #881370

#제출 시각아이디문제언어결과실행 시간메모리
881370Beerus13구경하기 (JOI13_watching)C++14
100 / 100
229 ms16216 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const int N = 2e3 + 5;
const int mod = 1e9 + 7;

int n, P, Q;
int a[N];
int dp[N][N];

bool check(int w) {
    memset(dp, 0x3f, sizeof(dp));
    dp[0][0] = 0;
    for(int i = 1; i <= n; ++i) {
        int kp = lower_bound(a + 1, a + n + 1, a[i] + w) - a - 1;
        int kq = lower_bound(a + 1, a + n + 1, a[i] + 2 * w) - a - 1;
        for(int j = 0; j <= P; ++j) {
            dp[kp][j + 1] = min(dp[kp][j + 1], dp[i - 1][j]);
            dp[kq][j] = min(dp[kq][j], dp[i - 1][j] + 1);
        }
    }
    for(int i = 0; i <= P; ++i) if(dp[n][i] <= Q) return true;
    return false;
}

void solve() {
    cin >> n >> P >> Q;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    if(n <= P + Q) {
        cout << 1 << '\n';
        return;
    }
    sort(a + 1, a + n + 1);
    int l = 1, r = (int)1e9, ans = -1;
    while(l <= r) {
        int m = l + r >> 1;
        if(check(m)) ans = m, r = m - 1;
        else l = m + 1;
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int test = 1;
    // cin >> test;
    while(test--) solve();
    return 0;
}

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

watching.cpp: In function 'void solve()':
watching.cpp:36:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |         int m = l + r >> 1;
      |                 ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...