Submission #396393

# Submission time Handle Problem Language Result Execution time Memory
396393 2021-04-29T23:21:35 Z 4fecta Road Construction (JOI21_road_construction) C++17
7 / 100
5616 ms 24428 KB
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)

const int MN = 750005;

int n, k, x, y, bit[MN];
pii a[MN];

void upd(int x, int val) {
    for (int i = x; i < MN; i += i & -i) bit[i] += val;
}

int qry(int x) {
    int ret = 0;
    for (int i = x; i > 0; i -= i & -i) ret += bit[i];
    return ret;
}

int cost(pii p, pii q) {
    return max(abs(p.f - q.f), abs(p.s - q.s));
}

int get(vector<int> &v, int num) {
    int lo = 0, hi = v.size() - 1, mid;
    while (lo <= hi) {
        mid = (lo + hi) >> 1;
        if (v[mid] == num) return mid + 1;
        else if (v[mid] < num) lo = mid + 1;
        else hi = mid - 1;
    }
    abort();
    return -1;
}

int count(int d) {
    int ret = 0;
    memset(bit, 0, sizeof(bit));
    vector<int> ys;
    for (int i = 1; i <= n; i++) {
        ys.push_back(a[i].s);
        ys.push_back(a[i].s - d);
        ys.push_back(a[i].s + d);
    }
    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
    int id = 1;
    for (int i = 1; i <= n; i++) {
        while (a[i].f - a[id].f > d) upd(get(ys, a[id].s), -1), id++;
        ret += qry(get(ys, a[i].s + d)) - qry(get(ys, a[i].s - d) - 1);
        //printf("lol %lld %lld\n", mp[a[i].s + d], mp[a[i].s - d]);
        if (ret >= k) return ret;
        upd(get(ys, a[i].s), 1);
    }
    return ret;
}

int32_t main() {
    boost();

    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> x >> y;
        a[i] = {x + y, x - y};
        //printf("%lld %lld\n", a[i].f, a[i].s);
    }
    sort(a + 1, a + n + 1);
    int lo = 1, hi = 1e10, mid;
    while (lo < hi) {
        mid = (lo + hi) >> 1;
        if (count(mid) >= k) hi = mid;
        else lo = mid + 1;
    }
    //printf("cnt %lld\n", count(2));
    printf("%lld\n", lo);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 6220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2462 ms 24256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4398 ms 24244 KB Output is correct
2 Correct 5184 ms 24324 KB Output is correct
3 Correct 13 ms 6188 KB Output is correct
4 Correct 1600 ms 24428 KB Output is correct
5 Correct 2434 ms 24252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4398 ms 24244 KB Output is correct
2 Correct 5184 ms 24324 KB Output is correct
3 Correct 13 ms 6188 KB Output is correct
4 Correct 1600 ms 24428 KB Output is correct
5 Correct 2434 ms 24252 KB Output is correct
6 Incorrect 5616 ms 24332 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 6220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 6220 KB Output isn't correct
2 Halted 0 ms 0 KB -