Submission #799877

# Submission time Handle Problem Language Result Execution time Memory
799877 2023-08-01T07:27:21 Z phoenix Road Construction (JOI21_road_construction) C++17
100 / 100
1657 ms 13448 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int n, k;
vector<pair<ll, ll>> v;

vector<ll> ans;

bool check(ll mid) {

    ans.clear();
    set<pair<ll, ll>> st;
    st.insert({v[0].second, 0});
    int l = 0;
    for(int i = 1; i < n; i++) {
        while(v[i].first - v[l].first > mid) {
            st.erase({v[l].second, l});
            l++;
        }
        auto it = st.lower_bound({v[i].second - mid, -1});
        while(it != st.end() && abs(v[i].second - it->first) <= mid) {
            ans.push_back({max(abs(v[i].first - v[it->second].first), abs(v[i].second - v[it->second].second))});
            it++;
        }
        if((int)ans.size() > k) return 0;
        st.insert({v[i].second, i});
    }
    return 1;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n >> k;
    v.resize(n);
    for(int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        v[i] = {x + y, x - y};
    }
    sort(v.begin(), v.end());
    ll l = 0, r = (ll)1e10;
    while(r - l > 1) {
        ll mid = (l + r) / 2;
        if(check(mid)) l = mid;
        else r = mid;
    }
    check(l);
    // cout << l << ' ' << r << '\n';
    sort(ans.begin(), ans.end());
    while((int)ans.size() < k) ans.push_back(r);
    for(ll c : ans) 
        cout << c << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 90 ms 5012 KB Output is correct
2 Correct 92 ms 5024 KB Output is correct
3 Correct 88 ms 5064 KB Output is correct
4 Correct 86 ms 5032 KB Output is correct
5 Correct 86 ms 3912 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 305 ms 10504 KB Output is correct
2 Correct 320 ms 10512 KB Output is correct
3 Correct 76 ms 4864 KB Output is correct
4 Correct 244 ms 10308 KB Output is correct
5 Correct 257 ms 10412 KB Output is correct
6 Correct 259 ms 10636 KB Output is correct
7 Correct 214 ms 9864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 9216 KB Output is correct
2 Correct 260 ms 9224 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 90 ms 7044 KB Output is correct
5 Correct 316 ms 9460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 9216 KB Output is correct
2 Correct 260 ms 9224 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 90 ms 7044 KB Output is correct
5 Correct 316 ms 9460 KB Output is correct
6 Correct 399 ms 9292 KB Output is correct
7 Correct 340 ms 9200 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 303 ms 9276 KB Output is correct
11 Correct 104 ms 7116 KB Output is correct
12 Correct 373 ms 9460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 5012 KB Output is correct
2 Correct 92 ms 5024 KB Output is correct
3 Correct 88 ms 5064 KB Output is correct
4 Correct 86 ms 5032 KB Output is correct
5 Correct 86 ms 3912 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 731 ms 7964 KB Output is correct
8 Correct 752 ms 7940 KB Output is correct
9 Correct 93 ms 5124 KB Output is correct
10 Correct 391 ms 7304 KB Output is correct
11 Correct 239 ms 7104 KB Output is correct
12 Correct 295 ms 7932 KB Output is correct
13 Correct 341 ms 6596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 5012 KB Output is correct
2 Correct 92 ms 5024 KB Output is correct
3 Correct 88 ms 5064 KB Output is correct
4 Correct 86 ms 5032 KB Output is correct
5 Correct 86 ms 3912 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 305 ms 10504 KB Output is correct
8 Correct 320 ms 10512 KB Output is correct
9 Correct 76 ms 4864 KB Output is correct
10 Correct 244 ms 10308 KB Output is correct
11 Correct 257 ms 10412 KB Output is correct
12 Correct 259 ms 10636 KB Output is correct
13 Correct 214 ms 9864 KB Output is correct
14 Correct 263 ms 9216 KB Output is correct
15 Correct 260 ms 9224 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 90 ms 7044 KB Output is correct
18 Correct 316 ms 9460 KB Output is correct
19 Correct 399 ms 9292 KB Output is correct
20 Correct 340 ms 9200 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 303 ms 9276 KB Output is correct
24 Correct 104 ms 7116 KB Output is correct
25 Correct 373 ms 9460 KB Output is correct
26 Correct 731 ms 7964 KB Output is correct
27 Correct 752 ms 7940 KB Output is correct
28 Correct 93 ms 5124 KB Output is correct
29 Correct 391 ms 7304 KB Output is correct
30 Correct 239 ms 7104 KB Output is correct
31 Correct 295 ms 7932 KB Output is correct
32 Correct 341 ms 6596 KB Output is correct
33 Correct 1657 ms 13288 KB Output is correct
34 Correct 1597 ms 13388 KB Output is correct
35 Correct 998 ms 12624 KB Output is correct
36 Correct 520 ms 13448 KB Output is correct
37 Correct 531 ms 13412 KB Output is correct
38 Correct 682 ms 12048 KB Output is correct