Submission #227708

# Submission time Handle Problem Language Result Execution time Memory
227708 2020-04-28T14:45:46 Z PeppaPig Watching (JOI13_watching) C++14
100 / 100
260 ms 16248 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e3+5;

int n, p, q;
int pos[N], dp[N][N];

bool f(int mid) {
    fill_n(dp[0], N * N, 1e9);

    int l1 = 1, l2 = 1;
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        while(pos[i] - pos[l1] >= mid) ++l1;
        while(pos[i] - pos[l2] >= 2 * mid) ++l2;

        for(int j = 0; j <= n; j++) {
            dp[i][j] = dp[l2 - 1][j] + 1;
            if(j) dp[i][j] = min(dp[i][j], dp[l1 - 1][j - 1]);
        }
    }
    for(int i = 0; i <= p; i++) if(dp[n][i] <= q)
        return true;
    return false;
}

int main() {
    scanf("%d %d %d", &n, &p, &q);
    for(int i = 1; i <= n; i++) scanf("%d", pos + i);
    sort(pos + 1, pos + 1 + n);

    int l = 1, r = 1e9;
    while(l < r) {
        int mid = (l + r) >> 1;
        if(f(mid)) r = mid;
        else l = mid + 1;
    }
    printf("%d\n", r);

    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &p, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:31:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%d", pos + i);
                                 ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 78 ms 16000 KB Output is correct
2 Correct 80 ms 16000 KB Output is correct
3 Correct 78 ms 16000 KB Output is correct
4 Correct 77 ms 16000 KB Output is correct
5 Correct 86 ms 16232 KB Output is correct
6 Correct 79 ms 16000 KB Output is correct
7 Correct 80 ms 16100 KB Output is correct
8 Correct 80 ms 16000 KB Output is correct
9 Correct 78 ms 16000 KB Output is correct
10 Correct 78 ms 16000 KB Output is correct
11 Correct 78 ms 16128 KB Output is correct
12 Correct 79 ms 16000 KB Output is correct
13 Correct 83 ms 16000 KB Output is correct
14 Correct 79 ms 16000 KB Output is correct
15 Correct 78 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 239 ms 16096 KB Output is correct
2 Correct 78 ms 16000 KB Output is correct
3 Correct 237 ms 16120 KB Output is correct
4 Correct 244 ms 16248 KB Output is correct
5 Correct 245 ms 16128 KB Output is correct
6 Correct 240 ms 16128 KB Output is correct
7 Correct 244 ms 16120 KB Output is correct
8 Correct 236 ms 16120 KB Output is correct
9 Correct 236 ms 16120 KB Output is correct
10 Correct 252 ms 16248 KB Output is correct
11 Correct 240 ms 16120 KB Output is correct
12 Correct 240 ms 16120 KB Output is correct
13 Correct 245 ms 16128 KB Output is correct
14 Correct 260 ms 16120 KB Output is correct
15 Correct 247 ms 16248 KB Output is correct