답안 #655150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655150 2022-11-03T11:30:32 Z hail 구경하기 (JOI13_watching) C++17
50 / 100
1000 ms 7764 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]{};

bool check(int w)
{
    int dp[p+1][q+1]{};
    //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 = INF;

    if(p+q>=n)
    {
        cout<<1;
        return;
    }
    while(high>low)
    {
        int mid = (high+low)/2;
        if(check(mid)) high = mid;
        else low = mid+1;
    }

    assert(high==low);

    cout<<high;


}

signed main()
{
    fast_io;

    int t=1; 
    //cin>>t;
    while(t--)
    {
        solve();
    }
    cout<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 320 KB Output is correct
12 Correct 3 ms 324 KB Output is correct
13 Correct 1 ms 284 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 208 ms 1064 KB Output is correct
9 Correct 204 ms 1080 KB Output is correct
10 Correct 256 ms 1660 KB Output is correct
11 Correct 144 ms 1664 KB Output is correct
12 Execution timed out 1047 ms 7764 KB Time limit exceeded
13 Halted 0 ms 0 KB -