Submission #770900

# Submission time Handle Problem Language Result Execution time Memory
770900 2023-07-02T05:55:52 Z joshuaZ Road Construction (JOI21_road_construction) C++17
0 / 100
726 ms 13316 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int mxN = 250002;

int n, k;
ll path[4 * mxN];
pll a[mxN];


bool solve(ll d){
    set<pll> st;
    int c = 1;
    for (int i = 1, j = 1; i <= n; i++){
        while (a[i].first - a[j].first > d){
            st.erase({a[j].second, a[j].first});
            j++;
        }
        auto l = st.lower_bound({a[i].second - d, -1e10});
        auto r = st.upper_bound({a[i].second + d, -1e10});
        for (auto it = l; it != r; it++){
            path[c] = max(abs((*it).first - a[i].second), abs((*it).second - a[i].first));
            if (++c >= 4 * mxN){
                return true;
            }
        }
        st.insert({a[i].second, a[i].first});
    }

    if (c >= k){
        return true;
    } else {
        return false;
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k;
    //xi + yi - (xj + yj) <= val
    //xi - yi - (xj - yj) <= val
    for (int i = 1; i <= n; i++){
        ll x, y; cin >> x >> y;
        a[i].first = x + y;
        a[i].second = x - y;
    }
    sort(a + 1, a + 1 + n);

    ll lo = 1, hi = 2e9, ans = -1;
    while (lo <= hi){
        ll mid = lo + (hi - lo) / 2;
        if (solve(mid)){
            ans = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }

    solve(ans);
    sort(path + 1, path + 1 + k);

    for (int i = 1; i <= k; i++){
        cout << path[i] << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 5368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 389 ms 13316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 707 ms 12132 KB Output is correct
2 Correct 726 ms 12236 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 707 ms 12132 KB Output is correct
2 Correct 726 ms 12236 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 5368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 5368 KB Output isn't correct
2 Halted 0 ms 0 KB -