답안 #170994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170994 2019-12-27T00:27:43 Z silxikys 구경하기 (JOI13_watching) C++14
100 / 100
499 ms 16356 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 2005;
int N, P, Q;
ll A[maxn];

int dp[maxn][maxn];
//[i-1'th one covered][# small used] = # of large needed
//

int jmpSmall[maxn], jmpBig[maxn];

int f(int i, int j) {
    if (i > N) return 0;
    int& res = dp[i][j];
    if (res != -1) return res;
    //take big one
    res = 1+f(jmpBig[i],j);
    if (j < P) res = min(res,f(jmpSmall[i],j+1));
    return res;
}

bool poss(ll w) {
    memset(dp,-1,sizeof dp);
    int pt = 0;
    for (int i = 1; i <= N; i++) {
        while (pt <= N && A[pt] < A[i]+w) pt++;
        jmpSmall[i] = pt;
    }
    pt = 0;
    for (int i = 1; i <= N; i++) {
        while (pt <= N && A[pt] < A[i]+2*w) pt++;
        jmpBig[i] = pt;
    }
    return f(1,0) <= Q;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> P >> Q;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    sort(A+1,A+N+1);
    ll lo = 0, hi = 1e9+9;
    while (lo + 1 < hi) {
        ll w = (lo+hi)/2;
        if (poss(w)) hi = w;
        else lo = w;
    }
    cout << hi << endl;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 16120 KB Output is correct
2 Correct 41 ms 16132 KB Output is correct
3 Correct 40 ms 16076 KB Output is correct
4 Correct 40 ms 16120 KB Output is correct
5 Correct 39 ms 16120 KB Output is correct
6 Correct 42 ms 16088 KB Output is correct
7 Correct 42 ms 16128 KB Output is correct
8 Correct 38 ms 16080 KB Output is correct
9 Correct 42 ms 16128 KB Output is correct
10 Correct 39 ms 16120 KB Output is correct
11 Correct 40 ms 16128 KB Output is correct
12 Correct 42 ms 16104 KB Output is correct
13 Correct 40 ms 16120 KB Output is correct
14 Correct 41 ms 16120 KB Output is correct
15 Correct 40 ms 16120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 16056 KB Output is correct
2 Correct 38 ms 16120 KB Output is correct
3 Correct 395 ms 16356 KB Output is correct
4 Correct 431 ms 16224 KB Output is correct
5 Correct 70 ms 16120 KB Output is correct
6 Correct 455 ms 16220 KB Output is correct
7 Correct 43 ms 16168 KB Output is correct
8 Correct 81 ms 16224 KB Output is correct
9 Correct 183 ms 16120 KB Output is correct
10 Correct 499 ms 16332 KB Output is correct
11 Correct 81 ms 16120 KB Output is correct
12 Correct 399 ms 16352 KB Output is correct
13 Correct 41 ms 16120 KB Output is correct
14 Correct 41 ms 16120 KB Output is correct
15 Correct 41 ms 16120 KB Output is correct