Submission #102827

# Submission time Handle Problem Language Result Execution time Memory
102827 2019-03-27T16:59:11 Z popovicirobert Watching (JOI13_watching) C++14
100 / 100
208 ms 14184 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]]);
            }
            if(dp[i][j] == n + 1) {
                return 1;
            }
        }
    }
    return 0;
}

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 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 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 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 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 114 ms 11640 KB Output is correct
4 Correct 31 ms 8952 KB Output is correct
5 Correct 12 ms 1024 KB Output is correct
6 Correct 208 ms 14184 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 10 ms 1280 KB Output is correct
9 Correct 17 ms 3840 KB Output is correct
10 Correct 44 ms 8696 KB Output is correct
11 Correct 15 ms 1024 KB Output is correct
12 Correct 78 ms 8056 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 384 KB Output is correct