답안 #1107348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107348 2024-11-01T06:37:50 Z nasir_bashirov 구경하기 (JOI13_watching) C++11
50 / 100
58 ms 15952 KB
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define db long double
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
// #define int long long
 
const int sz = 2e3 + 5;
int n, p, q, dp[sz][sz], a[sz];
 
int check(int w){
    for(int i = 1; i <= n; i++){
        int i1 = 0, i2 = 0;
        int l = 1, r = n - 1;
        while(l <= r){
            int mid = (l + r) / 2;
            if(a[mid] + w <= a[i]){
                i1 = mid;
                l = mid + 1;
            }
            else{
                r = mid - 1;
            }
        }
        l = 1, r = n - 1;
        while(l <= r){
            int mid = (l + r) / 2;
            if(a[mid] + 2 * w <= a[i]){
                i2 = mid;
                l = mid + 1;
            }
            else{
                r = mid - 1;
            }
        }
        for(int j = 1; j <= p; j++){
            // while(i1 + 1 <= n and a[i1 + 1] + w <= a[i]) i1++;
            // while(i2 + 1 <= n and a[i2 + 1] + w * 2 <= a[i]) i2++;
            dp[i][j] = min(dp[i2][j] + 1, dp[i1][j - 1]);
        }
    }
    return dp[n][p];
}
 
void fmain(){
    fastio;
    cin >> n >> p >> q;
    if(p + q >= n){
        cout << 1;
        return;
    }
    for(int j = 1; j <= n; j++) dp[j][0] = 1e9;
    p = min(n, p), q = min(n, q);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    int l = 1, r = 1e9 / (p + q), res = -1;
    while(l <= r){
        int mid = (l + r) / 2;
        if(check(mid) <= q){
            res = mid;
            r = mid - 1;
        }
        else{
            l = mid + 1;
        }
    }
    cout << res;
}
 
signed main(){
    int tmr = 1;
    // cin >> tmr;
    while(tmr--){
        fmain();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2552 KB Output is correct
9 Correct 1 ms 2604 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 15440 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 7 ms 15440 KB Output is correct
8 Correct 8 ms 15440 KB Output is correct
9 Correct 30 ms 15952 KB Output is correct
10 Correct 58 ms 15952 KB Output is correct
11 Correct 9 ms 15584 KB Output is correct
12 Correct 32 ms 15952 KB Output is correct
13 Correct 7 ms 15440 KB Output is correct
14 Correct 7 ms 15428 KB Output is correct
15 Incorrect 9 ms 15440 KB Output isn't correct
16 Halted 0 ms 0 KB -