답안 #289671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289671 2020-09-02T22:24:20 Z rocks03 구경하기 (JOI13_watching) C++14
100 / 100
734 ms 35064 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pld pair<long double, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define SZ(x) ((int)(x).size())
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 2e3+100;
int N, P, Q;
ll a[MAXN], nxt[2][MAXN], memo[MAXN][MAXN];

void read(){
    cin >> N >> P >> Q;
    for(int i = 0; i < N; i++) cin >> a[i];
}

int f(int q, int ind, ll w){
    if(ind == N){
        return 0;
    }
    if(memo[q][ind] != -1){
        return memo[q][ind];
    }
    int ans = P+1;
    int j = nxt[0][ind];
    ans = min(ans, f(q, j, w) + 1);
    if(q){
        int j = nxt[1][ind];
        ans = min(ans, f(q-1, j, w));
    }
    memo[q][ind] = ans;
    return memo[q][ind];
}

bool good(ll w){
    if(P + Q >= N) return true;
    for(int i = 0; i < N; i++){
        nxt[0][i] = upper_bound(a+i, a+N, a[i] + w - 1) - a;
        nxt[1][i] = upper_bound(a+i, a+N, a[i] + 2*w - 1) - a;
    }
    memset(memo, -1, sizeof(memo));
    return (f(Q, 0, w) <= P);
}

void solve(){
    read();
    sort(a, a+N);
    ll l = 0, r = 1e10;
    while(r - l > 1){
        ll m = (l + r) / 2;
        if(good(m)) r = m;
        else l = m;
    }
    cout << r;
}

int main(){
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 34816 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 168 ms 34816 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 168 ms 34816 KB Output is correct
8 Correct 168 ms 34920 KB Output is correct
9 Correct 165 ms 34816 KB Output is correct
10 Correct 163 ms 34816 KB Output is correct
11 Correct 166 ms 34816 KB Output is correct
12 Correct 163 ms 35064 KB Output is correct
13 Correct 164 ms 34812 KB Output is correct
14 Correct 168 ms 34816 KB Output is correct
15 Correct 164 ms 34816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 34936 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 170 ms 35064 KB Output is correct
8 Correct 297 ms 34944 KB Output is correct
9 Correct 201 ms 34944 KB Output is correct
10 Correct 206 ms 35064 KB Output is correct
11 Correct 734 ms 35044 KB Output is correct
12 Correct 482 ms 35064 KB Output is correct
13 Correct 172 ms 35064 KB Output is correct
14 Correct 166 ms 34944 KB Output is correct
15 Correct 167 ms 34944 KB Output is correct