답안 #945271

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945271 2024-03-13T15:34:43 Z mariamp1 구경하기 (JOI13_watching) C++14
100 / 100
162 ms 16236 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
const int N = 2000 + 5;
int n, p, q;
int a[N];
set<pair<int, int>> st;
int dp[N][N];
bool check(int mid){
    for(int i = 1; i <= n; i++){
        for (int j = 0; j <= n; j++) dp[i][j] = 1e9;
        auto it = st.lower_bound({a[i] - mid + 1, 0});
        it--; int l1 = (*it).second;
        auto it1 = st.lower_bound({a[i] - 2 * mid + 1, 0});
        it1--; int l2 = (*it1).second;

        for(int j = 0; j <= i; j++){
            ///             a[i]-mid+1     a[i]
            if (j == 0) dp[i][j] = dp[l2][j] + 1;
            else dp[i][j] = min(dp[l1][j - 1], dp[l2][j] + 1);
            if (i == n && j <= p && dp[i][j] <= q) return 1;
        }
    }
    return 0;
}
int main(){
    cin >> n >> p >> q;
    p = min(p, n);
    q = min(q, n);
    st.insert({-1e9, 0});
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        st.insert({a[i], i});
    }
    int l = 1, r = 1e9;
    int ans = 0;
    while(l <= r){
        int mid = l + (r-l)/2;
        if(check(mid)){
            r = mid-1;
            ans = mid;
        }else {
            l = mid + 1;
        }
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 16220 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 111 ms 16232 KB Output is correct
4 Correct 118 ms 16216 KB Output is correct
5 Correct 120 ms 16232 KB Output is correct
6 Correct 112 ms 16232 KB Output is correct
7 Correct 122 ms 16216 KB Output is correct
8 Correct 118 ms 16220 KB Output is correct
9 Correct 114 ms 16232 KB Output is correct
10 Correct 117 ms 16220 KB Output is correct
11 Correct 117 ms 16216 KB Output is correct
12 Correct 123 ms 16232 KB Output is correct
13 Correct 136 ms 16236 KB Output is correct
14 Correct 115 ms 16220 KB Output is correct
15 Correct 149 ms 16216 KB Output is correct