Submission #102826

# Submission time Handle Problem Language Result Execution time Memory
102826 2019-03-27T16:58:13 Z popovicirobert Watching (JOI13_watching) C++14
100 / 100
890 ms 16124 KB
#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;
    int pa = 0, pb = 0;
    for(i = 0; i <= n; i++) {
        while(arr[pa] - arr[i] < w) {
            pa++;
        }
        while(arr[pb] - arr[i] < 2LL * w) {
            pb++;
        }
        nxt_a[i] = pa;
        nxt_b[i] = pb;
    }
    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 time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 768 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 447 ms 12208 KB Output is correct
4 Correct 88 ms 8960 KB Output is correct
5 Correct 23 ms 1024 KB Output is correct
6 Correct 890 ms 16124 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 15 ms 1280 KB Output is correct
9 Correct 23 ms 3840 KB Output is correct
10 Correct 74 ms 8704 KB Output is correct
11 Correct 23 ms 1152 KB Output is correct
12 Correct 168 ms 8064 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct