Submission #867847

# Submission time Handle Problem Language Result Execution time Memory
867847 2023-10-29T15:09:25 Z hungnt Watching (JOI13_watching) C++14
100 / 100
151 ms 16176 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2002;

int n, a, b;
int p[N], dp[N][N];

bool check(int w)
{
    memset(dp, 0x3f, sizeof dp);
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++)
    {
        int j1 = upper_bound(p + 1, p + n + 1, p[i] - w) - p - 1;
        int j2 = upper_bound(p + 1, p + n + 1, p[i] - 2 * w) - p - 1;
        for(int k = 0; k <= a; k++)
        {
            if(k) dp[i][k] = min(dp[i][k], dp[j1][k - 1]);
            dp[i][k] = min(dp[i][k], dp[j2][k] + 1);
        }
    }
    for(int i = 0; i <= a; i++)
        if(dp[n][i] <= b) return 1;
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++) cin >> p[i];
    if(n <= a + b) return cout << 1, 0;
    sort(p + 1, p + n + 1);
    int l = 2, r = 1000000000, mid, ans = r;
    while(l <= r)
    {
        mid = (l + r) >> 1;
        if(check(mid))
        {
            ans = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 16144 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 13 ms 15960 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 13 ms 15964 KB Output is correct
8 Correct 19 ms 15964 KB Output is correct
9 Correct 13 ms 15964 KB Output is correct
10 Correct 18 ms 16148 KB Output is correct
11 Correct 20 ms 15964 KB Output is correct
12 Correct 22 ms 16148 KB Output is correct
13 Correct 14 ms 15960 KB Output is correct
14 Correct 15 ms 15964 KB Output is correct
15 Correct 16 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 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 476 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 19 ms 16176 KB Output is correct
8 Correct 42 ms 15964 KB Output is correct
9 Correct 83 ms 16160 KB Output is correct
10 Correct 151 ms 15960 KB Output is correct
11 Correct 26 ms 15964 KB Output is correct
12 Correct 89 ms 16144 KB Output is correct
13 Correct 19 ms 15964 KB Output is correct
14 Correct 26 ms 16104 KB Output is correct
15 Correct 31 ms 15964 KB Output is correct