답안 #963500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963500 2024-04-15T07:41:25 Z BhavayGoyal 구경하기 (JOI13_watching) C++14
50 / 100
7 ms 5212 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using oset = 
            tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"

const int MOD = 1e9+7;
const int inf = 1e9;
const ll linf = 1e18;

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


// -------------------------------------------------- Main Code --------------------------------------------------

int dp[101][101][101];
int n, nxtP[101], nxtQ[101];

int sol(int idx, int p, int q) {
    if (idx >= n) return 1;
    if (dp[idx][p][q] != -1) return dp[idx][p][q];
    int ans = 0;
    if (p) ans |= sol(nxtP[idx]+1, p-1, q);
    if (q) ans |= sol(nxtQ[idx]+1, p, q-1);
    return dp[idx][p][q] = ans;
}

void sol() {
    int p, q; cin >> n >> p >> q;
    p = min(p, n); q = min(q, n);

    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr+n);

    auto fiss = [&](int mid) {
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= p; j++) {
                for (int k = 0; k <= q; k++) dp[i][j][k] = -1;
            }
        }
        for (int i = 0; i < n; i++) {
            nxtP[i] = upper_bound(arr, arr+n, arr[i]+mid-1) - arr - 1;
            nxtQ[i] = upper_bound(arr, arr+n, arr[i]+2*mid-1) - arr - 1;
        }

        return sol(0, p, q);
    };

    int i = 0, j = inf, ans = inf;
    while (i <= j) {
        int mid = (i+j)/2;
        if (fiss(mid)) ans = mid, j = mid-1;
        else i = mid+1;
    }
    cout << ans << endl;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t; 
    while (t--) {
        sol();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 7 ms 4440 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 3 ms 3672 KB Output is correct
12 Correct 4 ms 3672 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 5212 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -