이 제출은 이전 버전의 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)){
multiset<pair<ll,pii> >d;
for(int i=0;i<n-1;i++)d.insert({dist(a[i],a[i+1]),{i,i+1}});
vector<ll>ans;
while(ans.size()<k){
pair<ll,pii>x=*d.begin();
ans.pb(x.f);
int l=x.s.f,r=x.s.s;
d.erase(x);
if(r<n-1)
d.insert({dist(a[l],a[r+1]),{l,r+1}});
}
for(ll to:ans){
cout<<to<<"\n";
}
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:43:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
43 | while(ans.size()<k){
| ~~~~~~~~~~^~
# | 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... |