답안 #867848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867848 2023-10-29T15:11:56 Z hungnt 구경하기 (JOI13_watching) C++14
100 / 100
155 ms 16208 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 = 1, 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 15964 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 14 ms 15964 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 14 ms 16140 KB Output is correct
8 Correct 26 ms 15964 KB Output is correct
9 Correct 19 ms 15964 KB Output is correct
10 Correct 24 ms 15964 KB Output is correct
11 Correct 13 ms 15960 KB Output is correct
12 Correct 14 ms 15964 KB Output is correct
13 Correct 27 ms 15964 KB Output is correct
14 Correct 14 ms 15964 KB Output is correct
15 Correct 13 ms 15964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 16148 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 16 ms 16148 KB Output is correct
8 Correct 29 ms 15964 KB Output is correct
9 Correct 72 ms 15960 KB Output is correct
10 Correct 155 ms 15960 KB Output is correct
11 Correct 32 ms 16208 KB Output is correct
12 Correct 100 ms 15964 KB Output is correct
13 Correct 22 ms 15964 KB Output is correct
14 Correct 22 ms 16148 KB Output is correct
15 Correct 22 ms 15964 KB Output is correct