Submission #355794

# Submission time Handle Problem Language Result Execution time Memory
355794 2021-01-23T03:18:48 Z eyangch Watching (JOI13_watching) C++17
100 / 100
244 ms 16236 KB
#include <bits/stdc++.h>

using namespace std;

int N, P, Q;
int a[100000];
int dp[2001][2001]; // [num of events][large cameras]
int jmps[2001], jmpl[2001];

bool works(int mid){
    fill(dp[0], dp[N]+Q+1, 1e9);
    fill(dp[0], dp[0]+Q+1, 0);
    iota(jmps, jmps+N+1, -1);
    iota(jmpl, jmpl+N+1, -1);
    for(int i = N-1; i >= 0; i--){
        int idxs = upper_bound(a, a+N, a[i]-mid) - a - 1;
        int idxl = upper_bound(a, a+N, a[i]-2*mid) - a - 1;
        //cout << idxs << " " << idxl << endl;
        jmps[i] = idxs;
        jmpl[i] = idxl;
    }
    /*for(int i = 0; i < N; i++){
        cout << jmps[i] << " ";
    }cout << endl;
    for(int i = 0; i < N; i++){
        cout << jmpl[i] << " ";
    }cout << endl;*/
    for(int i = 1; i <= N; i++){
        int pvs = jmps[i-1]+1;
        int pvl = jmpl[i-1]+1;
        dp[i][0] = dp[pvs][0] + 1;
        for(int j = 1; j <= Q; j++){
            dp[i][j] = min(dp[pvl][j-1], dp[pvs][j] + 1);
        }
    }
    /*int pvsN = jmps[N];
    int pvlN = jmpl[N];
    //cout << pvsN << " " << pvlN << endl;
    return (min(dp[pvlN][Q-1], dp[pvsN][Q]+1) <= P);*/
    return (dp[N][Q] <= P);
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> P >> Q;
    if(P+Q >= N){
        cout << 1 << endl;
        return 0;
    }
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a, a+N);
    int lo = 0, hi = 1e9, mid = 0;
    //cout << works(4) << endl;
    while(lo < hi){
        mid = (lo + hi) / 2;
        if(works(mid)){
            hi = mid-1;
        }else{
            lo = mid+1;
        }
    }
    while(works(mid)) mid--;
    while(!works(mid)) mid++;
    cout << mid << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1132 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 4 ms 1132 KB Output is correct
8 Correct 4 ms 1132 KB Output is correct
9 Correct 4 ms 1132 KB Output is correct
10 Correct 5 ms 1132 KB Output is correct
11 Correct 4 ms 1132 KB Output is correct
12 Correct 4 ms 1132 KB Output is correct
13 Correct 4 ms 1132 KB Output is correct
14 Correct 4 ms 1132 KB Output is correct
15 Correct 4 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 16108 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 99 ms 16108 KB Output is correct
8 Correct 165 ms 16108 KB Output is correct
9 Correct 113 ms 16108 KB Output is correct
10 Correct 114 ms 16108 KB Output is correct
11 Correct 244 ms 16236 KB Output is correct
12 Correct 186 ms 16112 KB Output is correct
13 Correct 108 ms 16108 KB Output is correct
14 Correct 111 ms 16108 KB Output is correct
15 Correct 104 ms 16108 KB Output is correct