답안 #1001684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001684 2024-06-19T06:58:29 Z coolboy19521 구경하기 (JOI13_watching) C++17
0 / 100
1000 ms 856 KB
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"

#define int long long

using namespace std;

const int sz = 2e3 + 6;
const int inf = 1e18;

vector<vector<int>> aj[sz];
int a[sz];
int n, p, q;
bool f;

void dfs(int v, int cl, int cr) {
    if (cl > p || cr > q) return;
    if (v == n + 1) {
        f |= (cl <= p && cr <= q);
    } else {
        for (auto& u : aj[v]) {
            if (f) return;
            dfs(u[0], cl + u[1], cr + u[2]);
        }
    }
}

bool che(int mi) {
    for (int i = 1; i <= n; i ++) {
        aj[i].clear();
        int d = lower_bound(a + 1, a + n + 1, a[i] + mi) - &a[i];
        int c = lower_bound(a + 1, a + n + 1, a[i] + 2 * mi) - &a[i];
        aj[i].push_back({i + d, 1, 0});
        aj[i].push_back({i + c, 0, 1});
    }
    f = false;
    dfs(1, 0, 0);
    return f;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    cin >> n >> p >> q;

    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
    }

    sort(a + 1, a + n + 1);
    a[n + 1] = inf;

    int mn = inf;

    for (int i = 2; i <= n; i ++) {
        mn = min(mn, a[i] - a[i - 1]);
    }

    int le, ri;
    le = 0, ri = (a[n] - a[1]) / (p + q) + 10;

    while (1 < ri - le) {
        int mi = le + (ri - le) / 2;

        if (che(mi)) {
            ri = mi;
        } else {
            le = mi;
        }
    }

    cout << ri << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Execution timed out 1099 ms 348 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 856 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 5 ms 852 KB Output is correct
4 Correct 4 ms 844 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 856 KB Output is correct
7 Execution timed out 1098 ms 604 KB Time limit exceeded
8 Halted 0 ms 0 KB -