답안 #1102171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102171 2024-10-17T15:31:46 Z Icelast 구경하기 (JOI13_watching) C++17
100 / 100
339 ms 16244 KB
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 1e9+9;
struct normalize{
    vector<ll> poi, pot;
    void add(ll x){
        poi.push_back(x);
    }
    void start(){
        sort(poi.begin(), poi.end());
        pot.push_back(poi[0]);
        for(int i = 1; i < (int)poi.size(); i++){
            if(poi[i] != poi[i-1]){
                pot.push_back(poi[i]);
            }
        }
    }
    int encode(ll x){
        return lower_bound(pot.begin(), pot.end(), x) - pot.begin()+1;
    }
};
void solve(){
    int n, P, Q;
    cin >> n >> P >> Q;
    P = min(P, n);
    vector<ll> a(n+1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a.begin()+1, a.end());
    vector<vector<int>> p(n+1, vector<int>(3));
    //minimum number of big camera need for prefix-i event, j small camera used
    vector<vector<int>> f(n+1, vector<int>(P+1));
    auto check = [&](ll x) -> bool{
        for(int i = 1; i <= n; i++){
            p[i][1] = lower_bound(a.begin()+1, a.end(), a[i]-x+1) - a.begin();
            p[i][2] = lower_bound(a.begin()+1, a.end(), a[i]-x*2+1) - a.begin();
        }
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= P; j++){
                f[i][j] = INF;
            }
        }
        f[0][0] = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 0; j <= P; j++){
                if(j > 0) f[i][j] = min(f[i][j], f[p[i][1]-1][j-1]);
                f[i][j] = min(f[i][j], f[p[i][2]-1][j]+1);
            }
        }
        int mn = INF;
        for(int j = 0; j <= P; j++){
            mn = min(mn, f[n][j]);
        }
        return mn <= Q;
    };
    ll l = 1, r = 1e9, mid;
    while(l <= r){
        mid = (l+r)/2;
        if(check(mid)){
            r = mid-1;
        }else{
            l = mid+1;
        }
    }
    cout << l;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 508 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 592 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 276 ms 12368 KB Output is correct
4 Correct 327 ms 16244 KB Output is correct
5 Correct 16 ms 1272 KB Output is correct
6 Correct 339 ms 16208 KB Output is correct
7 Correct 5 ms 592 KB Output is correct
8 Correct 25 ms 1616 KB Output is correct
9 Correct 123 ms 6384 KB Output is correct
10 Correct 333 ms 15444 KB Output is correct
11 Correct 24 ms 1368 KB Output is correct
12 Correct 166 ms 8276 KB Output is correct
13 Correct 8 ms 760 KB Output is correct
14 Correct 9 ms 852 KB Output is correct
15 Correct 9 ms 596 KB Output is correct