Submission #934595

# Submission time Handle Problem Language Result Execution time Memory
934595 2024-02-27T16:26:50 Z borisAngelov Watching (JOI13_watching) C++17
50 / 100
27 ms 27188 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 505;

int n, p, q;

int a[maxn];

int findPos(int pos, int delta)
{
    int l = 1;
    int r = pos;

    while (l <= r)
    {
        int mid = (l + r) / 2;

        if (a[pos] - a[mid] <= delta)
        {
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }

    return l;
}

bool dp[maxn][maxn][maxn];
int prvSmall[maxn];
int prvBig[maxn];

bool check(int w)
{
    for (int i = 1; i <= n; ++i)
    {
        prvSmall[i] = findPos(i, w - 1);
        prvBig[i] = findPos(i, 2 * w - 1);
    }

    for (int i = 0; i <= p; ++i)
    {
        for (int j = 0; j <= q; ++j)
        {
            dp[0][i][j] = true;

            if (i + j >= 1)
            {
                dp[1][i][j] = true;
            }
        }
    }

    for (int pos = 2; pos <= n; ++pos)
    {
        for (int currp = 0; currp <= p; ++currp)
        {
            for (int currq = 0; currq <= q; ++currq)
            {
                dp[pos][currp][currq] = false;

                if (currp >= 1)
                {
                    dp[pos][currp][currq] |= dp[pos][currp - 1][currq];
                    dp[pos][currp][currq] |= dp[prvSmall[pos] - 1][currp - 1][currq];
                }

                if (currq >= 1)
                {
                    dp[pos][currp][currq] |= dp[pos][currp][currq - 1];
                    dp[pos][currp][currq] |= dp[prvBig[pos] - 1][currp][currq - 1];
                }
            }
        }
    }

    return dp[n][p][q];
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n >> p >> q;

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

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

    p = min(p, n);
    q = min(q, n);
    p = min(p, n - q);

    if (q == n || p == n)
    {
        cout << 1 << endl;
        return 0;
    }

    int l = 1;
    int r = 1000000000;

    while (l <= r)
    {
        int mid = (l + r) / 2;

        if (check(mid) == true)
        {
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }

    cout << l << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 27076 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 11 ms 27188 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 4 ms 26968 KB Output is correct
8 Correct 4 ms 26972 KB Output is correct
9 Correct 5 ms 26972 KB Output is correct
10 Correct 12 ms 26972 KB Output is correct
11 Correct 13 ms 26972 KB Output is correct
12 Correct 27 ms 26972 KB Output is correct
13 Correct 4 ms 26972 KB Output is correct
14 Correct 4 ms 26972 KB Output is correct
15 Correct 4 ms 26968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -