#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
if (x>y)x=y;
return x>y;
}
template <class _T>
bool chmax(_T &x, const _T &y){
if (x<y)x=y;
return x<y;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e18+7;
const ll mod=1e9+7;
const ll N=2e5+5;
const ld eps=1e-9;
vector<pair<ll,ll>> v;
multiset<ll> ms;
ll n,k;
ll i,j,mn=inf;
map<pair<pair<ll,ll>,pair<ll,ll>>,bool> vis;
ll dis(ll i,ll j){
return abs(v[i].fr-v[j].fr)+abs(v[i].sc-v[j].sc);
}
bool cmp(pair<ll,ll> a,pair<ll,ll> b){
return a.sc<b.sc;
}
void upd_ans(ll i,ll j){
if(dis(i,j)>=mn || vis[{v[i],v[j]}])return;
vis[{v[i],v[j]}]=true;
vis[{v[j],v[i]}]=true;
ms.ins(dis(i,j));
if((ll)ms.sz>k)ms.erase(--ms.end());
if((ll)ms.sz==k)chmin(mn,*ms.rbegin());
}
void rec(ll l,ll r){
if(r-l<=3){
for(i=l;i<r;i++){
for(j=i+1;j<=r;j++)upd_ans(i,j);
}
sort(v.begin()+l,v.begin()+r+1,cmp);
return ;
}
ll m=(l+r)/2;
rec(l,m),rec(m+1,r);
vector<pair<ll,ll>> v2(r-l+1);
ll mx=v[m].fr;
merge(v.begin()+l,v.begin()+m+1,v.begin()+m+1,v.begin()+r+1,v2.begin(),cmp);
copy(v2.begin(),v2.begin()+r-l+1,v.begin()+l);
vll vv;
for(i=l;i<=r;i++){
if(mn<=abs(v[i].fr-mx))continue;
for(j=vv.sz-1;j>=0;j--){
if(mn<=abs(v[i].sc-v[vv[j]].sc))break;
upd_ans(i,vv[j]);
}
vv.pb(i);
}
}
void solve(){
ll i,j;
ll a,b;
cin>>n>>k;
for(i=0;i<n;i++){
cin>>a>>b;
v.pb({a,b});
}
sort(all(v));
rec(0,n-1);
for(auto i : ms) cout<<i<<endl;
}
signed main(){
start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
*/
Compilation message
road_construction.cpp: In function 'void solve()':
road_construction.cpp:90:7: warning: unused variable 'j' [-Wunused-variable]
90 | ll i,j;
| ^
road_construction.cpp: In function 'void fre(std::string)':
road_construction.cpp:36:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:36:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
647 ms |
67608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2712 ms |
282972 KB |
Output is correct |
2 |
Correct |
2687 ms |
281820 KB |
Output is correct |
3 |
Correct |
361 ms |
53844 KB |
Output is correct |
4 |
Correct |
2352 ms |
307704 KB |
Output is correct |
5 |
Correct |
1731 ms |
266384 KB |
Output is correct |
6 |
Correct |
1751 ms |
266592 KB |
Output is correct |
7 |
Correct |
1839 ms |
271600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
113 ms |
10120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
113 ms |
10120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
647 ms |
67608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
647 ms |
67608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |