답안 #389180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389180 2021-04-13T20:39:16 Z couplefire Road Construction (JOI21_road_construction) C++17
100 / 100
3688 ms 36820 KB
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000000000009ll
#define ll long long

int n, k;
vector<ll> ans;
set<pair<ll, ll>> st;
map<ll, vector<ll>> mp;
queue<pair<ll, ll>> active;

bool check(ll mid){
    ans.clear();
    st.clear();
    active = queue<pair<ll, ll>>();
    for(auto &i : mp){
        vector<ll> &v = i.second;
        ll x = i.first;
        while(!active.empty() && active.front().second < x-mid) st.erase(active.front()), active.pop();
        for(auto &y : v){
            auto it = st.lower_bound({y-mid, -INF});
            while(it != st.end() && (*it).first <= y+mid){
                ans.push_back(max(abs((*it).first-y),abs(x-(*it).second)));
                if((int)ans.size() > k) return 0;
                it = next(it);
            }
            st.insert({y, x});
            active.push({y, x});
        }
    }
    return 1;
}

int main(){
    // freopen("a.in", "r", stdin);
    // freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0; i<n; i++){
        ll a, b; cin >> a >> b;
        mp[a+b].push_back(a-b);
    }
    for(auto &x : mp) sort(x.second.begin(), x.second.end());
    ll lo = 1, hi = 4000000009;
    while(lo < hi){
        ll mid = lo+(hi-lo+1)/2;
        if(check(mid)) lo = mid;
        else hi = mid-1;
    }
    check(lo);
    sort(ans.begin(), ans.end());
    for(int i = 0; i<k; i++){
        if(i < (int)ans.size()) cout << ans[i] << endl;
        else cout << lo+1 << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 510 ms 5008 KB Output is correct
2 Correct 515 ms 5068 KB Output is correct
3 Correct 503 ms 5196 KB Output is correct
4 Correct 557 ms 5188 KB Output is correct
5 Correct 495 ms 3928 KB Output is correct
6 Correct 7 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1612 ms 30960 KB Output is correct
2 Correct 1613 ms 30908 KB Output is correct
3 Correct 485 ms 4908 KB Output is correct
4 Correct 1437 ms 30708 KB Output is correct
5 Correct 1415 ms 31028 KB Output is correct
6 Correct 1355 ms 31060 KB Output is correct
7 Correct 1299 ms 30292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1118 ms 27688 KB Output is correct
2 Correct 1199 ms 32716 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 756 ms 30600 KB Output is correct
5 Correct 453 ms 8872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1118 ms 27688 KB Output is correct
2 Correct 1199 ms 32716 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 756 ms 30600 KB Output is correct
5 Correct 453 ms 8872 KB Output is correct
6 Correct 1420 ms 32768 KB Output is correct
7 Correct 1299 ms 32836 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1217 ms 30632 KB Output is correct
11 Correct 643 ms 30576 KB Output is correct
12 Correct 449 ms 8768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 510 ms 5008 KB Output is correct
2 Correct 515 ms 5068 KB Output is correct
3 Correct 503 ms 5196 KB Output is correct
4 Correct 557 ms 5188 KB Output is correct
5 Correct 495 ms 3928 KB Output is correct
6 Correct 7 ms 332 KB Output is correct
7 Correct 1782 ms 16024 KB Output is correct
8 Correct 1760 ms 16004 KB Output is correct
9 Correct 506 ms 5196 KB Output is correct
10 Correct 1215 ms 14032 KB Output is correct
11 Correct 921 ms 13264 KB Output is correct
12 Correct 839 ms 6604 KB Output is correct
13 Correct 873 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 510 ms 5008 KB Output is correct
2 Correct 515 ms 5068 KB Output is correct
3 Correct 503 ms 5196 KB Output is correct
4 Correct 557 ms 5188 KB Output is correct
5 Correct 495 ms 3928 KB Output is correct
6 Correct 7 ms 332 KB Output is correct
7 Correct 1612 ms 30960 KB Output is correct
8 Correct 1613 ms 30908 KB Output is correct
9 Correct 485 ms 4908 KB Output is correct
10 Correct 1437 ms 30708 KB Output is correct
11 Correct 1415 ms 31028 KB Output is correct
12 Correct 1355 ms 31060 KB Output is correct
13 Correct 1299 ms 30292 KB Output is correct
14 Correct 1118 ms 27688 KB Output is correct
15 Correct 1199 ms 32716 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 756 ms 30600 KB Output is correct
18 Correct 453 ms 8872 KB Output is correct
19 Correct 1420 ms 32768 KB Output is correct
20 Correct 1299 ms 32836 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1217 ms 30632 KB Output is correct
24 Correct 643 ms 30576 KB Output is correct
25 Correct 449 ms 8768 KB Output is correct
26 Correct 1782 ms 16024 KB Output is correct
27 Correct 1760 ms 16004 KB Output is correct
28 Correct 506 ms 5196 KB Output is correct
29 Correct 1215 ms 14032 KB Output is correct
30 Correct 921 ms 13264 KB Output is correct
31 Correct 839 ms 6604 KB Output is correct
32 Correct 873 ms 4948 KB Output is correct
33 Correct 3688 ms 36820 KB Output is correct
34 Correct 3628 ms 36772 KB Output is correct
35 Correct 2756 ms 29644 KB Output is correct
36 Correct 1100 ms 11764 KB Output is correct
37 Correct 1138 ms 11828 KB Output is correct
38 Correct 1189 ms 11428 KB Output is correct