이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
template <typename T>
using pbds_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
main(){
int n, k; cin >> n >> k;
pair<int, int> arr[n];
for (int x = 0; x < n; x++){
cin >> arr[x].first >> arr[x].second;
}
//consider manhattan distance trick?
for (int x = 0; x < n; x++){
arr[x] = {arr[x].first + arr[x].second, arr[x].first - arr[x].second};
}
sort(arr, arr+n); //sorted by x-coord
//now chebyshev distance, dist = max of difference
//I want to bsearch, but bsearch only gives location of boundary; I need sum of boundary
int l = 0, r = 4'000'000'000LL, ans = 4'000'000'000LL;
while (l <= r){
int m = (l+r)/2;
int cnt = 0;
pbds_multiset<int> ms;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for (int x = 0; x < n; x++){
while (!pq.empty() && pq.top().first <= arr[x].first){
ms.erase(ms.find_by_order(ms.order_of_key(arr[ pq.top().second ].second)));
pq.pop();
}
cnt += ms.order_of_key(arr[x].second+m + 1) - ms.order_of_key(arr[x].second - m);
ms.insert(arr[x].second);
pq.push({arr[x].first+m+1, x});
}
if (cnt < k){
l = m+1;
}
else{
ans = m;
r = m-1;
}
}
vector<int> clown;
for (int x = 0; x < n; x++){
for (int y = x+1; y <= min(x+k+2, n-1); y++){
if ( abs(arr[x].first - arr[y].first) > ans) break;
clown.push_back( max( abs(arr[x].first - arr[y].first), abs(arr[x].second - arr[y].second) ) );
}
}
sort(clown.begin(), clown.end());
for (int x = 0; x < k; x++) cout << clown[x] << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
road_construction.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |