106032024-04-06 14:24:33Valaki2Drónfutárcpp17Wrong answer 0/100293ms60448 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 1e5;

struct edge {
    int a, b;
    int wei;
    bool operator < (const edge & other) const {
        return wei < other.wei;
    }
};

int n;
int x[1 + maxn], y[1 + maxn];

vector<pii > endpoints;

void add(int a, int b) {
    endpoints.pb(mp(min(a, b), max(a, b)));
}

struct point {
    int x, y, idx;
    bool operator < (const point &other) const {
        return x + y < other.x + other.y;
    }
};

map<int, int> m;

void find_batch() {
    vector<point> points;
    for(int i = 1; i <= n; i++) {
        points.pb(point{x[i], y[i], i});
    }
    sort(points.begin(), points.end());
    for(point cur : points) {
        auto it = m.lower_bound(cur.y - cur.x);
        while(it != m.end()) {
            int other = it->se;
            it = m.erase(it);
            if(x[other] > x[cur.idx]) {
                break;
            }
            add(other, cur.idx);
        }
        m[cur.y - cur.x] = cur.idx;
    }
}

void find_relevant_edges() {
    find_batch();
    for(int i = 1; i <= n; i++) {
        x[i] *= -1;
    }
    find_batch();
    for(int i = 1; i <= n; i++) {
        swap(x[i], y[i]);
    }
    find_batch();
    for(int i = 1; i <= n; i++) {
        x[i] *= -1;
    }
    find_batch();
    sort(endpoints.begin(), endpoints.end());
    endpoints.resize(unique(endpoints.begin(), endpoints.end()) - endpoints.begin());
}

int par[1 + maxn];
int sz[1 + maxn];

void create_set(int a) {
    par[a] = a;
    sz[a] = 1;
}

int find_set(int a) {
    if(a == par[a]) {
        return a;
    }
    return find_set(par[a]);
}

bool union_sets(int a, int b) {
    a = find_set(a), b = find_set(b);
    if(a == b) {
        return false;
    }
    if(sz[a] > sz[b]) {
        swap(a, b);
    }
    sz[b] += sz[a];
    par[a] = b;
    return true;
}

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }
    vector<edge> edges;
    find_relevant_edges();
    for(const pii &p : endpoints) {
        edges.pb(edge {p.fi, p.se, abs(x[p.fi] - x[p.se]) + abs(y[p.fi] - y[p.se])});
    }
    /*for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            edges.pb(edge {i, j, abs(x[i] - x[j]) + abs(y[i] - y[j])});
        }
    }*/
    sort(edges.begin(), edges.end());
    for(int i = 1; i <= n; i++) {
        create_set(i);
    }
    int ans = 0;
    for(edge e : edges) {
        if(union_sets(e.a, e.b)) {
            ans = max(ans, e.wei);
        }
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2048 KiB
2Wrong answer284ms56408 KiB
subtask20/15
3Wrong answer4ms4680 KiB
4Wrong answer4ms4924 KiB
5Wrong answer4ms5104 KiB
6Wrong answer4ms5360 KiB
7Accepted3ms5040 KiB
subtask30/15
8Wrong answer4ms4680 KiB
9Wrong answer4ms4924 KiB
10Wrong answer4ms5104 KiB
11Wrong answer4ms5360 KiB
12Accepted3ms5040 KiB
13Accepted4ms5380 KiB
14Wrong answer4ms5656 KiB
15Wrong answer4ms5884 KiB
16Wrong answer4ms6008 KiB
17Wrong answer4ms6040 KiB
subtask40/35
18Wrong answer4ms4680 KiB
19Wrong answer4ms4924 KiB
20Wrong answer4ms5104 KiB
21Wrong answer4ms5360 KiB
22Accepted3ms5040 KiB
23Accepted4ms5380 KiB
24Wrong answer4ms5656 KiB
25Wrong answer4ms5884 KiB
26Wrong answer4ms6008 KiB
27Wrong answer4ms6040 KiB
28Wrong answer4ms6084 KiB
29Wrong answer56ms18172 KiB
30Wrong answer79ms20932 KiB
31Wrong answer79ms21336 KiB
32Accepted61ms25264 KiB
subtask50/35
33Wrong answer4ms4680 KiB
34Wrong answer4ms4924 KiB
35Wrong answer4ms5104 KiB
36Wrong answer4ms5360 KiB
37Accepted3ms5040 KiB
38Accepted4ms5380 KiB
39Wrong answer4ms5656 KiB
40Wrong answer4ms5884 KiB
41Wrong answer4ms6008 KiB
42Wrong answer4ms6040 KiB
43Wrong answer4ms6084 KiB
44Wrong answer56ms18172 KiB
45Wrong answer79ms20932 KiB
46Wrong answer79ms21336 KiB
47Accepted61ms25264 KiB
48Wrong answer136ms34812 KiB
49Wrong answer287ms60440 KiB
50Wrong answer293ms60448 KiB
51Wrong answer287ms60448 KiB
52Wrong answer286ms60448 KiB