Submission #138016

# Submission time Handle Problem Language Result Execution time Memory
138016 2019-07-28T22:37:40 Z MladenP Watching (JOI13_watching) C++17
100 / 100
469 ms 31968 KB
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 2010
lld N, P, Q, A[MAXN];
lld dp[MAXN][MAXN], l1[MAXN], l2[MAXN];
bool check(lld w) {
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= P; j++) dp[i][j] = INF;
    }
    for(int i = 1; i <= N; i++) {
        for(int j = i-1; j >= 0; j--) {
            if(A[j] <= A[i]-w && A[j+1] > A[i]-w) l1[i] = j;
            if(A[j] <= A[i]-2*w && A[j+1] > A[i]-2*w) l2[i] = j;
        }
    }
    for(int i = 0; i <= P; i++) dp[0][i] = 0;
    for(int i = 1; i <= N; i++) {
        for(int j = 0; j <= P; j++) {
            if(j > 0) dp[i][j] = min(dp[l1[i]][j-1], dp[l2[i]][j]+1);
            else dp[i][j] = dp[l2[i]][j]+1;
        }
    }
    for(int i = 0; i <= P; i++) if(dp[N][i] <= Q) return true;
    return false;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
    cin >> N >> P >> Q;
    A[0] = -2000000000;
    for(int i = 1; i <= N; i++) cin >> A[i];
    sort(A+1, A+1+N);
    if(P+Q >= N) {
        cout << 1 << endl;
        return 0;
    }
    lld l = 1, r = 1000000000, rez = r;
    while(l <= r) {
        if(check(mid)) rez = mid, r = mid-1;
        else l = mid+1;
    }
    cout << rez << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 764 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 8524 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 96 ms 8696 KB Output is correct
8 Correct 115 ms 10484 KB Output is correct
9 Correct 224 ms 20216 KB Output is correct
10 Correct 469 ms 31968 KB Output is correct
11 Correct 108 ms 9848 KB Output is correct
12 Correct 269 ms 23800 KB Output is correct
13 Correct 95 ms 8568 KB Output is correct
14 Correct 96 ms 8868 KB Output is correct
15 Correct 96 ms 8696 KB Output is correct