Submission #102825

#TimeUsernameProblemLanguageResultExecution timeMemory
102825popovicirobert구경하기 (JOI13_watching)C++14
100 / 100
990 ms16140 KiB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x))

using namespace std;

const ll INF = 1e15;
const int MAXN = 2005;

int dp[MAXN + 1][MAXN + 1];
ll arr[MAXN + 1];

int nxt_a[MAXN + 1], nxt_b[MAXN + 1];

inline bool check(ll w, int n, int a, int b) {
    int i, j;
    for(i = 0; i <= n; i++) {
        for(j = i; j <= n + 1; j++) {
            if(arr[j] - arr[i] >= w) {
                nxt_a[i] = j;
                break;
            }
        }
        for(j = i; j <= n + 1; j++) {
            if(arr[j] - arr[i] >= 2LL * w) {
                nxt_b[i] = j;
                break;
            }
        }
    }
    dp[0][0] = 1;
    for(int s = 1; s <= a + b; s++) {
        for(i = 0; i <= min(a, s); i++) {
            j = s - i;
            if(j > b) {
                continue;
            }
            dp[i][j] = 0;
            if(i > 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j]);
                dp[i][j] = max(dp[i][j], nxt_a[dp[i - 1][j]]);
            }
            if(j > 0) {
                dp[i][j] = max(dp[i][j], dp[i][j - 1]);
                dp[i][j] = max(dp[i][j], nxt_b[dp[i][j - 1]]);
            }
        }
    }
    return dp[a][b] == n + 1;
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, a, b;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> a >> b;
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    sort(arr + 1, arr + n + 1);
    arr[n + 1] = INF;
    a = min(n, a), b = min(b, n);
    int res = 0;
    for(int step = 1 << 29; step; step >>= 1) {
        if(check(res + step, n, a, b) == 0) {
            res += step;
        }
    }
    cout << res + 1;
    //cin.close();
    //cout.close();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...