Submission #590025

# Submission time Handle Problem Language Result Execution time Memory
590025 2022-07-05T13:24:51 Z Valaki2 Road Construction (JOI21_road_construction) C++14
100 / 100
1609 ms 14832 KB
#include <bits/stdc++.h>
using namespace std;

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

const int inf = 4e9 + 42;

int n, k;
vector<pii > points;

inline int new_x(pii a) {
    return a.fi - a.se;
}

inline int new_y(pii a) {
    return a.fi + a.se;
}

inline int dist(pii a, pii b) {
    return abs(a.fi - b.fi) + abs(a.se - b.se);
}

bool cmp_1(pii a, pii b) {
    if(new_x(a) == new_x(b)) {
        return (a.fi < b.fi);
    }
    return new_x(a) < new_x(b);
}

struct cmp_2 {
    bool operator()(const pii &a, const pii &b) {
        if(new_y(a) == new_y(b)) {
            return (a.se < b.se);
        }
        return new_y(a) < new_y(b);
    }
};

vector<int> real_ans;

bool check(int l) {
    set<pii, cmp_2> s;
    vector<int> ans;
    int idx_2 = 0;
    for(int idx_1 = 0; idx_1 < n; idx_1++) {
        while(idx_2 < idx_1 && (new_x(points[idx_1]) - new_x(points[idx_2])) > l) {
            s.erase(s.find(points[idx_2]));
            idx_2++;
        }
        pii cur = points[idx_1];
        auto it = s.lower_bound(mp(cur.fi, cur.se - l));
        while(it != s.end()) {
            pii nei = *it;
            int d = dist(cur, nei);
            if(d <= l) {
                ans.pb(d);
                if((int) ans.size() >= k + 1) {
                    return false;
                }
            } else {
                break;
            }
            it++;
        }
        s.insert(cur);
    }
    real_ans = ans;
    return true;
}

void solve() {
    cin >> n >> k;
    points.assign(n, mp(0, 0));
    for(int i = 0; i < n; i++) {
        cin >> points[i].fi >> points[i].se;
    }
    sort(points.begin(), points.end(), cmp_1);
#ifdef __DEBUG__
    for(pii p : points) {
        cout << p.fi << " " << p.se << "\n";
    }
#endif
    int l = 1, r = inf;
    while(l < r - 1) {
        int mid = (l + r) / 2;
        if(check(mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }
#ifdef __DEBUG__
    cout << l << "\n";
    cout << "-----\n";
#endif
    check(l);
    sort(real_ans.begin(), real_ans.end());
    real_ans.resize(k, r);
    for(int cur : real_ans) {
        cout << cur << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 127 ms 9172 KB Output is correct
2 Correct 111 ms 11792 KB Output is correct
3 Correct 141 ms 9220 KB Output is correct
4 Correct 119 ms 8972 KB Output is correct
5 Correct 127 ms 9380 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 410 ms 14100 KB Output is correct
2 Correct 413 ms 13880 KB Output is correct
3 Correct 124 ms 6380 KB Output is correct
4 Correct 304 ms 13648 KB Output is correct
5 Correct 301 ms 10716 KB Output is correct
6 Correct 296 ms 10716 KB Output is correct
7 Correct 286 ms 10728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 267 ms 5048 KB Output is correct
2 Correct 313 ms 5108 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 149 ms 4772 KB Output is correct
5 Correct 400 ms 4608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 267 ms 5048 KB Output is correct
2 Correct 313 ms 5108 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 149 ms 4772 KB Output is correct
5 Correct 400 ms 4608 KB Output is correct
6 Correct 430 ms 4564 KB Output is correct
7 Correct 418 ms 4564 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 364 ms 4564 KB Output is correct
11 Correct 121 ms 4560 KB Output is correct
12 Correct 391 ms 4624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 9172 KB Output is correct
2 Correct 111 ms 11792 KB Output is correct
3 Correct 141 ms 9220 KB Output is correct
4 Correct 119 ms 8972 KB Output is correct
5 Correct 127 ms 9380 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 790 ms 11132 KB Output is correct
8 Correct 760 ms 14416 KB Output is correct
9 Correct 119 ms 8988 KB Output is correct
10 Correct 523 ms 12564 KB Output is correct
11 Correct 252 ms 11128 KB Output is correct
12 Correct 374 ms 6344 KB Output is correct
13 Correct 436 ms 8580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 9172 KB Output is correct
2 Correct 111 ms 11792 KB Output is correct
3 Correct 141 ms 9220 KB Output is correct
4 Correct 119 ms 8972 KB Output is correct
5 Correct 127 ms 9380 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 410 ms 14100 KB Output is correct
8 Correct 413 ms 13880 KB Output is correct
9 Correct 124 ms 6380 KB Output is correct
10 Correct 304 ms 13648 KB Output is correct
11 Correct 301 ms 10716 KB Output is correct
12 Correct 296 ms 10716 KB Output is correct
13 Correct 286 ms 10728 KB Output is correct
14 Correct 267 ms 5048 KB Output is correct
15 Correct 313 ms 5108 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 149 ms 4772 KB Output is correct
18 Correct 400 ms 4608 KB Output is correct
19 Correct 430 ms 4564 KB Output is correct
20 Correct 418 ms 4564 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 364 ms 4564 KB Output is correct
24 Correct 121 ms 4560 KB Output is correct
25 Correct 391 ms 4624 KB Output is correct
26 Correct 790 ms 11132 KB Output is correct
27 Correct 760 ms 14416 KB Output is correct
28 Correct 119 ms 8988 KB Output is correct
29 Correct 523 ms 12564 KB Output is correct
30 Correct 252 ms 11128 KB Output is correct
31 Correct 374 ms 6344 KB Output is correct
32 Correct 436 ms 8580 KB Output is correct
33 Correct 1609 ms 13620 KB Output is correct
34 Correct 1584 ms 13588 KB Output is correct
35 Correct 985 ms 14832 KB Output is correct
36 Correct 608 ms 8804 KB Output is correct
37 Correct 680 ms 8416 KB Output is correct
38 Correct 663 ms 10256 KB Output is correct