Submission #968608

# Submission time Handle Problem Language Result Execution time Memory
968608 2024-04-23T17:27:13 Z LOLOLO Road Construction (JOI21_road_construction) C++14
6 / 100
284 ms 9584 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 3e5 + 50;
vector <ll> lst;
vector <pair <ll, ll>> point;
int lim;

void solve(ll k) {
    multiset <pair <ll, ll>> save;
    int j = 0; 
    for (int i = 0; i < sz(point); i++) {
        while (point[i].f - point[j].f > k) {
            save.erase(save.find({point[j].s, point[j].f}));
            j++;
        }

        auto it = save.lower_bound({point[j].s - k, -1});
        while (it != save.end()) {
            if (abs(it -> f - point[i].s) > k)
                break;

            lst.pb(max(abs(it -> f - point[i].s), abs(it -> s - point[i].f)));
            if (sz(lst) >= lim)
                return;

            it = next(it);
        }

        save.insert({point[i].s, point[i].s});
    }
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n >> lim;

    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        point.pb({x + y, x - y});
    }

    sort(all(point));

    ll l = 0, r = 4e9, m, ans;
    while (l <= r) {
        m = (l + r) / 2;
        lst.clear();
        solve(m);
        if (sz(lst) >= lim) {
            ans = m;
            r = m - 1;
        } else {
            l = m + 1;
        }
    }

    lst.clear();
    solve(ans - 1);

    while (sz(lst) < lim)
        lst.pb(ans);

    sort(all(lst));

    for (auto x : lst)
        cout << x << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2016 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 284 ms 9364 KB Output is correct
2 Correct 284 ms 9400 KB Output is correct
3 Correct 73 ms 5080 KB Output is correct
4 Correct 235 ms 9380 KB Output is correct
5 Correct 220 ms 9584 KB Output is correct
6 Correct 211 ms 9400 KB Output is correct
7 Correct 207 ms 8768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 8640 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 8640 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2016 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2016 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -