답안 #867250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867250 2023-10-28T02:48:46 Z HaiHoang 구경하기 (JOI13_watching) C++17
100 / 100
212 ms 31936 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll inf=1e9;
ll n, P, Q;
vector<ll> a;
ll L[2005][2];
ll dp[2005][2005];
bool check(ll w)
{
    for(ll i=0; i<=n+2; i++)
    {
        for(ll j=0; j<=n+2; j++)
        {
            dp[i][j] = inf;
        }
    }
    for(ll i=1; i<=n; i++)
    {
        L[i][0] = lower_bound(a.begin()+1,a.end(), a[i] - w + 1) - a.begin();
        L[i][1] = lower_bound(a.begin()+1,a.end(), a[i] - 2 * w + 1) - a.begin();
    }
    for(ll i=0; i<=P; i++)  dp[0][i] = 0;

    for(ll i=1; i<=n; i++)
    {
        for(ll p=0; p<=P; p++)
        {
            dp[i][p] = min((p > 0 ? dp[L[i][0] - 1][p - 1] : inf), dp[L[i][1] - 1][p] + 1);

        }
    }
    return dp[n][P] <= Q;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> P >> Q;
    P = min(P, n);
    Q = min(Q, n);
    a.resize(n + 1);
    for(ll i=1; i<=n; i++) cin >> a[i];
    sort(a.begin()+1,a.end());
    ll l = 1, r = inf, ans = 0;
    while (l <= r)
    {
        int m = (l + r) >> 1;
        if (check(m))
        {
            ans = m, r = m - 1;
        }
        else l = m + 1;
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 31836 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 185 ms 31836 KB Output is correct
4 Correct 206 ms 31832 KB Output is correct
5 Correct 98 ms 31936 KB Output is correct
6 Correct 206 ms 31932 KB Output is correct
7 Correct 80 ms 31832 KB Output is correct
8 Correct 94 ms 31836 KB Output is correct
9 Correct 136 ms 31832 KB Output is correct
10 Correct 212 ms 31936 KB Output is correct
11 Correct 86 ms 31832 KB Output is correct
12 Correct 153 ms 31836 KB Output is correct
13 Correct 81 ms 31836 KB Output is correct
14 Correct 83 ms 31836 KB Output is correct
15 Correct 86 ms 31928 KB Output is correct