제출 #473785

#제출 시각아이디문제언어결과실행 시간메모리
473785Lam_lai_cuoc_doiWatching (JOI13_watching)C++17
100 / 100
93 ms16020 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

template <class T>
void read(T &x)
{
    x = 0;
    register int c;
    while ((c = getchar()) && (c > '9' || c < '0'))
        ;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
}

constexpr bool typetest = 0;
constexpr int N = 2e3 + 5;
constexpr int Inf = 1e9 + 7;

int n, q, p;
int a[N], cp(1), cq(2);
int dp[N][N];

void Read()
{
    cin >> n >> p >> q;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

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

bool Check(int v)
{
    for (int i = 1, ip = 1, iq = 1; i <= n; ++i)
    {
        while (ip < i && a[i] - a[ip] + 1 > cp * v)
            ++ip;
        while (iq < i && a[i] - a[iq] + 1 > cq * v)
            ++iq;

        for (int j = 0; j <= p; ++j)
        {
            dp[i][j] = dp[iq - 1][j] + 1;
            if (j)
                dp[i][j] = min(dp[i][j], dp[ip - 1][j - 1]);
        }
    }

    for (int i = 0; i <= p; ++i)
        if (dp[n][i] <= q)
            return true;
    return false;
}

void Solve()
{
    if (p + q >= n)
    {
        cout << 1;
        return;
    }

    if (p > q)
    {
        swap(p, q);
        swap(cp, cq);
    }

    int l = 1, m, h = 1e9;
    while (l <= h)
    {
        m = (l + h) / 2;
        if (Check(m))
            h = m - 1;
        else
            l = m + 1;
    }

    cout << l;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t(1);
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        //cout << "Case #" << _ << ": ";
        Read();
        Solve();
    }
    //cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

컴파일 시 표준 에러 (stderr) 메시지

watching.cpp: In function 'void read(T&)':
watching.cpp:12:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     register int c;
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...