This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,t;
cin>>n>>t;
pair<int,int>pr[n];
for(auto &i:pr)cin>>i.first>>i.second;
pair<int,int>por[n];
for(int i=0;i<n;i++)por[i]=pr[i];
sort(pr,pr+n);
map<pair<int,int>,bool>vis;
priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>>pq;
int mn=1000000000000000000ll,k=0;
for(int i=0;i<n;i++){
if(abs(pr[i].first)+abs(pr[i].second)<mn){mn=abs(pr[i].first)+abs(pr[i].second);k=i;}
}
pq.push({mn,pr[k]});
deque<pair<int,int>>g;
int x[]={-1,-1,-1,0,0,1,1,1};
int y[]={-1,1,0,1,-1,-1,1,0};
while(pq.size()){
pair<int,int>p=pq.top().second;
pq.pop();
if(vis[p])break;
vis[p]=1;
g.push_back(p);
for(int i=0;i<8;i++){
pair<int,int>pp=make_pair(p.first+x[i],p.second+y[i]);
int k=lower_bound(pr,pr+n,pp)-pr;
if(k!=n&&pr[k]==pp&&!vis[pp]){
pq.push({0,pp});
}
}
}
if(g.size()<n){cout<<"NO";}
else{
cout<<"YES\n";
map<pair<int,int>,int>mp;
for(int i=0;i<n;i++){
mp[g[i]]=i+1;
}
for(int i=0;i<n;i++)cout<<mp[por[i]]<<endl;
}
}
Compilation message (stderr)
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:42:16: warning: comparison of integer expressions of different signedness: 'std::deque<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
42 | if(g.size()<n){cout<<"NO";}
| ~~~~~~~~^~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |