Submission #96080

# Submission time Handle Problem Language Result Execution time Memory
96080 2019-02-05T16:28:35 Z Alexa2001 Watching (JOI13_watching) C++17
100 / 100
114 ms 16120 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 2005, inf = 1e9;

int N, P, Q, n;
int A[Nmax], a[Nmax], dp[Nmax][Nmax];

bool check(int W)
{
    int i, j = 1, k = 1, it;

    for(i=1; i<=N; ++i)
    {
        while(W - 1 < A[i] - A[j]) ++j;
        while(2*W - 1 < A[i] - A[k]) ++k;

        for(it=0; it<=i && it<=P; ++it)
            dp[i][it] = min( (it != 0 ? dp[j-1][it-1] : inf), dp[k-1][it] + 1);

        for(; it<=P; ++it) dp[i][it] = 0;
    }
    return (dp[N][P] <= Q);
}

int main()
{
  //  freopen("input", "r", stdin);

    int i;
    cin >> n >> P >> Q;
    for(i=1; i<=n; ++i) cin >> a[i];

    sort(a+1, a+n+1);

    for(i=1; i<=n; ++i)
        if(a[i] != a[i-1]) A[++N] = a[i];

    P = min(P, N); Q = min(Q, N);

    int st = 1, dr = inf, mid;
    while(st <= dr)
    {
        mid = (st+dr)/2;
        if(check(mid)) dr = mid-1;
            else st = mid+1;
    }
    cout << st << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 2 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8444 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 90 ms 15972 KB Output is correct
4 Correct 114 ms 15992 KB Output is correct
5 Correct 16 ms 8952 KB Output is correct
6 Correct 113 ms 15992 KB Output is correct
7 Correct 10 ms 8440 KB Output is correct
8 Correct 19 ms 9336 KB Output is correct
9 Correct 61 ms 14200 KB Output is correct
10 Correct 113 ms 15992 KB Output is correct
11 Correct 17 ms 9052 KB Output is correct
12 Correct 76 ms 16120 KB Output is correct
13 Correct 10 ms 8440 KB Output is correct
14 Correct 11 ms 8568 KB Output is correct
15 Correct 10 ms 8568 KB Output is correct