답안 #657173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
657173 2022-11-09T03:15:45 Z hail 구경하기 (JOI13_watching) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
using ll= long long;
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define inpint(x) int x; cin>>x
#define inpll(x) long long x; cin>>x
#define fl(i, n) for(int i=0; i<n; i++)
#define flo(i, n) for(int i=1; i<=n; i++)
#define int long long 
#define pi pair<int, int>
#define mp make_pair
#define ld long double
 
const int MOD = 7 + (int)1e9;
const int INF = (int)1e18;
 
//
 
int n, p, q;
int a[2005]{};
int dp[2005][2005]{};
 
bool check(int w)
{
    //p small q large
 
    for(int i=0; i<=p; i++)
    {
        for(int j=0; j<=q; j++)
        {
            //check p, q-1 and p-1, q
            if(j-1>=0)
            {
                int x = dp[i][j-1];
                auto it = upper_bound(a+1, a+n+1, x);
                int y = *it;
                int z = y + (2*w) - 1;
                it = upper_bound(a+1, a+n+1, z);
                it--;
                int t = *it;
                dp[i][j] = max(dp[i][j], t);
            }
            if(i-1>=0)
            {
                int x = dp[i-1][j];
                auto it = upper_bound(a+1, a+n+1, x);
                int y = *it;
                int z = y + (w) - 1;
                it = upper_bound(a+1, a+n+1, z);
                it--;
                int t = *it;
                dp[i][j] = max(dp[i][j], t);   
            }
 
            if(dp[i][j]>=a[n]) return true;
        }
    }
 
    return false;
}
 
void solve()
{
    cin>>n>>p>>q;
 
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
 
    sort(a+1, a+n+1);
 
    int low = 1;
    int high = 1000000000LL;
 
    if(p+q>=n)
    {
        cout<<1;
        return;
    }
 
    assert(p<=2000 && q<=2000);
 
    //assert(p<=2000 && q<=2000);
    int cnt = 0;
    while(high>low)
    {
        int mid = (high+low)/2;
        if(check(mid)) high = mid;
        else low = mid+1;
        cnt++;
        assert(cnt<40);
    }
 
    assert(high==low);
 
    cout<<high;
 
 
}
 
signed main()
{
    fast_io;
 
    int t=1; 
    //cin>>t;
    while(t--)
    {
        solve();
    }
    cout<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -