Submission #1001893

# Submission time Handle Problem Language Result Execution time Memory
1001893 2024-06-19T08:22:53 Z vjudge1 Watching (JOI13_watching) C++17
50 / 100
1000 ms 191900 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 nw[sz], nww[sz];
int n, p, q;
int a[sz];
bool f;
map<vector<int>,bool>vi;
 
void dfs(int v, int cl, int cr) {
    vi[{v,cl,cr}]=true;
    if (cl > p || cr > q) return;
    if (v == n + 1) {
        f |= (cl <= p && cr <= q);
    } else {
        for (auto& u : aj[v]) {
            if(vi[{u[0],cl+u[1],cr+u[2]}]) continue;
            // if(u[1] <= nw[v] || u[2] <= nww[v]) {
                dfs(u[0], cl + u[1], cr + u[2]);
            // }
            if (f) return;
        }
    }
}
 
bool che(int mi) {
    vi.clear();
    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});
        nw[i] = nww[i] = inf;
    }
    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 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';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 508 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 15 ms 1048 KB Output is correct
11 Correct 25 ms 1080 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 8 ms 1336 KB Output is correct
4 Correct 7 ms 1296 KB Output is correct
5 Correct 10 ms 1372 KB Output is correct
6 Correct 6 ms 1316 KB Output is correct
7 Correct 11 ms 1116 KB Output is correct
8 Execution timed out 1101 ms 191900 KB Time limit exceeded
9 Halted 0 ms 0 KB -