Submission #112145

# Submission time Handle Problem Language Result Execution time Memory
112145 2019-05-17T15:38:08 Z dolphingarlic Watching (JOI13_watching) C++14
0 / 100
30 ms 31996 KB
#include<bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
using namespace std;

int n, p, q;
int a[2005];
int dp[2005][2005]; // Max position you can get up to with at most i smaint and j big
                   // You clearly need at most N cameras

bool assign(int w) {
    dp[0][0] = 0;
    int ii = 1 , jj = 1;
    FOR(i, 1, n + 1) {
        while (a[i] - a[ii] + 1 > w) ii++;
        while (a[i] - a[jj] + 1 > 2 * w) jj++;
        FOR(j, 0, min(i, p) + 1) {
            if (j == 0) dp[i][j] = dp[jj - 1][j] + 1;
            else dp[i][j] = min(dp[jj - 1][j] + 1, dp[ii - 1][j - 1]), dp[i][j] = min(dp[i][j], dp[i][j - 1]);
        }
    }
    return dp[n][min(p, n)] <= q;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> p >> q;
    FOR(i, 1, n + 1) cin >> a[i];
    sort(a + 1, a + n + 1);
    fill_n(&dp[0][0], 2005 * 2005, q + 1);

    int l = 1, r = 1e9;
    while (l != r) {
        // cout << l << ' ' << r << endl;
        int mid = (l + r) >> 1;
        if (assign(mid)) r = mid - 1;
        else l = mid + 1;
    }
    cout << l << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16000 KB Output is correct
2 Runtime error 30 ms 31996 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16128 KB Output is correct
2 Runtime error 29 ms 31872 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -