Submission #881370

# Submission time Handle Problem Language Result Execution time Memory
881370 2023-12-01T07:55:50 Z Beerus13 Watching (JOI13_watching) C++14
100 / 100
229 ms 16216 KB
#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;
}

Compilation message

watching.cpp: In function 'void solve()':
watching.cpp:36:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |         int m = l + r >> 1;
      |                 ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 15968 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 24 ms 16176 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 26 ms 15964 KB Output is correct
8 Correct 24 ms 16168 KB Output is correct
9 Correct 20 ms 15964 KB Output is correct
10 Correct 24 ms 15964 KB Output is correct
11 Correct 18 ms 15960 KB Output is correct
12 Correct 24 ms 15964 KB Output is correct
13 Correct 29 ms 15964 KB Output is correct
14 Correct 26 ms 15964 KB Output is correct
15 Correct 19 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 15964 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 472 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 41 ms 15964 KB Output is correct
8 Correct 47 ms 15964 KB Output is correct
9 Correct 101 ms 16196 KB Output is correct
10 Correct 229 ms 16192 KB Output is correct
11 Correct 56 ms 15964 KB Output is correct
12 Correct 130 ms 16196 KB Output is correct
13 Correct 38 ms 16196 KB Output is correct
14 Correct 34 ms 15964 KB Output is correct
15 Correct 39 ms 16216 KB Output is correct