제출 #1352133

#제출 시각아이디문제언어결과실행 시간메모리
1352133maxphast구경하기 (JOI13_watching)C++20
0 / 100
4 ms8516 KiB
/*
* @Author: MaxPhast
* @File:   test.cpp
* @Date:   2026-04-13 21:02:51
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair <int , int>
#define iii pair <int , ii>
#define iiii pair <ii , ii>
#define FOR(i , l , r) for(int i = (l) , _r = (r) ; i <= _r ; ++ i)
#define FORD(i , r , l) for(int i = (r) , _l = (l) ; i >= _l ; -- i)
#define ALL(vec) vec.begin() , vec.end()
#define UNI(vec) sort(ALL(vec)) , vec.erase(unique(ALL(vec)) , vec.end())
#define pb push_back
#define MASK(i) (1ll << i)
#define BIT(mask , i) ((mask >> i) & 1ll)
#define ON(mask , i) (mask | MASK(i))
#define OFF(mask , i) (mask & (~MASK(i)))
#define TURN(mask , i) (mask ^ MASK(i))
#define BP(mask) __builtin_popcountll(mask)
#define sqr(x) (1ll * (x) * (x))
#define fi first
#define se second
#define oo (int)1e18
#define time() cerr << " \n " << "Time elapsed : " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms."
#define IO(TASK) if(fopen(#TASK".INP" , "r")){freopen(#TASK".INP" , "r" , stdin); freopen(#TASK".OUT" , "w" , stdout);}

template <class X , class Y>
    bool maxz(X &a , const Y b)
    {
        if(a < b)
        {
            a = b;
            return true;
        }
        return false;
    }
template <class X , class Y>
    bool minz(X &a , const Y b)
    {
        if(a > b)
        {
            a = b;
            return true;
        }
        return false;
    }

namespace MaxPhast
{

    const int N = 2e3 + 5;

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

    bool f(int w)
    {
        FOR(i , 0 , n)
            FOR(j , 0 , P)
                dp[i][j] = oo;

        dp[0][0] = 0;
        int p = 1 , q = 1;
        FOR(i , 1 , n)
        {
            while(p <= n && (a[p] - a[i] + 1) <= w)
                p ++;
            while(q <= n && (a[q] - a[i] + 1) <= 2 * w)
                q ++;

            FOR(j , 0 , P)
            {
                if(j - 1 >= 0)
                    minz(dp[p - 1][j] , dp[i - 1][j - 1]);
                minz(dp[q - 1][j] , dp[i - 1][j] + 1);
            }
        }
        
        int res = oo;
        FOR(j , 0 , P)
            minz(res , dp[n][j]);

        return res <= Q;
    }

    void solve()
    {
        cin >> n >> P >> Q;

        FOR(i , 1 , n)
            cin >> a[i];

        sort(a + 1 , a + 1 + n);
        minz(P , n);
        minz(Q , n);

        int l = 1 , r = 1e6 , res = 1e6 + 1;
        while(l <= r)
        {
            int mid = l + r >> 1;
            if(f(mid))
            {
                res = mid;
                r = mid - 1;
            }
            else
                l = mid + 1;
        }

        cout << res;
    }

}

signed main()
{
    ios_base :: sync_with_stdio(false) ; cin.tie(nullptr) ; cout.tie(nullptr) ;
    IO(test);
    MaxPhast :: solve();
    time();
}
/*

*/

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

watching.cpp: In function 'int main()':
watching.cpp:29:54: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 | #define IO(TASK) if(fopen(#TASK".INP" , "r")){freopen(#TASK".INP" , "r" , stdin); freopen(#TASK".OUT" , "w" , stdout);}
      |                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:122:5: note: in expansion of macro 'IO'
  122 |     IO(test);
      |     ^~
watching.cpp:29:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 | #define IO(TASK) if(fopen(#TASK".INP" , "r")){freopen(#TASK".INP" , "r" , stdin); freopen(#TASK".OUT" , "w" , stdout);}
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:122:5: note: in expansion of macro 'IO'
  122 |     IO(test);
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...