이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
using namespace std;
struct Point{
ll x,y;
Point(ll x,ll y):x(x),y(y){}
Point(){
}
};
ll dist(Point A,Point B){
return abs(A.x-B.x)+abs(A.y-B.y);
}
bool check(vector<Point>a){
for(Point A:a){
if(A.y!=0)return false;
}
return true;
}
bool comp(Point A,Point B){
if(A.x==B.x)return A.y<B.y;
return A.x<B.x;
}
void solve(){
int n;cin>>n;
int k;cin>>k;
vector<Point>a(n);
for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y;
sort(a.begin(),a.end(),comp);
if(check(a)){
vector<ll>vec;
for(int i=0;i<n;i++)vec.pb(a[i].x);
int l=0,r=1e15;
while(l+1<r){
ll mid=(l+r)/2;
ll ans=0;
for(int i=0;i<vec.size();i++){
int x=upper_bound(vec.begin(),vec.end(),vec[i]+mid)-vec.begin();
ans+=x-i-1;
if(ans>=k)break;
}
if(ans>=k)r=mid;
else l=mid;
}
multiset<ll>d;
for(int i=0;i<n;i++){
for(int j=i+1;j<n&&vec[j]<=vec[i]+r;j++)d.insert(dist(a[j],a[i]));
}
int ind=0;
for(ll to:d){
if(ind>=k)break;
cout<<to<<"\n";
ind++;
}
return;
}
multiset<ll>d;
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
d.insert(dist(a[i],a[j]));
}
}
int ind=0;
for(ll to:d){
if(ind>=k)break;
cout<<to<<"\n";
ind++;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
road_construction.cpp: In function 'void solve()':
road_construction.cpp:42:19: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+15' to '2147483647' [-Woverflow]
42 | int l=0,r=1e15;
| ^~~~
road_construction.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=0;i<vec.size();i++){
| ~^~~~~~~~~~~
# | 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... |