답안 #934571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934571 2024-02-27T15:47:45 Z borisAngelov 구경하기 (JOI13_watching) C++17
50 / 100
94 ms 27228 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);

    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 12 ms 27200 KB Output is correct
5 Correct 11 ms 26972 KB Output is correct
6 Correct 94 ms 26972 KB Output is correct
7 Correct 4 ms 26968 KB Output is correct
8 Correct 4 ms 26968 KB Output is correct
9 Correct 4 ms 26972 KB Output is correct
10 Correct 12 ms 26972 KB Output is correct
11 Correct 14 ms 26972 KB Output is correct
12 Correct 28 ms 26972 KB Output is correct
13 Correct 5 ms 26968 KB Output is correct
14 Correct 4 ms 26972 KB Output is correct
15 Correct 4 ms 27228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 472 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -