제출 #702040

#제출 시각아이디문제언어결과실행 시간메모리
702040Tien_Noob구경하기 (JOI13_watching)C++17
100 / 100
330 ms16076 KiB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 2e3;
int dp[N + 1][N + 1];
int last[N + 1][2];
int a[N + 1], p, q, 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 mid)
{
    for (int t = 1; t <= 2; ++ t)
    {
        int j = 1;
        for (int i = 1; i <= n; ++ i)
        {
            while(a[j] + 1LL * t * mid - 1 < a[i])
            {
                ++j;
            }
            last[i][t - 1] = j;
        }
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++ i)
    {
        for (int j = 0; j <= q; ++ j)
        {
            if (j > 0)
            {
                dp[i][j] = min(dp[i][j], dp[last[i][1] - 1][j - 1]);
            }
            dp[i][j] = min(dp[i][j], dp[last[i][0] - 1][j] + 1);
        }
    }
    return *min_element(dp[n], dp[n] + q + 1) <= p;
}
void solve()
{
    if (max(p, q) >= n)
    {
        cout << 1;
        return ;
    }
    int low = 1, high = 1e9;
    while(low <= high)
    {
        int mid = (low + high)/2;
        if (check(mid))
        {
            high = mid - 1;
        }
        else
        {
            low = mid + 1;
        }
    }
    cout << low;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

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

watching.cpp: In function 'int main()':
watching.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...