#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>pi;
const int oo = 1'000'000'000'000'000'000ll;
int dx[]={0,1,1,1,0,-1,-1,-1};
int dy[]={1,1,0,-1,-1,-1,0,1};
vector<int>ord;
vector<int>cur;
map<pi,int>have;
map<pi,int>idx;
map<pi,int>vis;
void dfs(pi cc){
vis[cc]=1;
cur.push_back(idx[cc]);
int x=cc.first,y=cc.second;
for(int k=0;k<8;k++){
int nx=x+dx[k];
int ny=y+dy[k];
if(have.find({nx,ny}) != have.end() && !vis[{nx,ny}]){
dfs({nx,ny});
return;
}
}
}
vector<int>boundary(set<pi> S){
vector<pi> X;
for(auto x:S)X.push_back(x);
sort(X.begin(),X.end(),[](pi x, pi y){
if(x.first != y.first)return x.first<y.first;
else return x.second>y.second;
});
have.clear();
cur.clear();
for(auto x:X)have[x]=1;
vis.clear();
dfs(X[0]);
return cur;
}
set<pi>ss;
map<int,pi>coord;
pi mn=make_pair(oo,oo);
map<pi,bool>done;
int n,t;
void test(){
priority_queue<pi,vector<pi>,greater<pi>>pq;
vector<int>ord;
pq.push(mn);
done[mn]=1;
while(pq.size()){
pi cur=pq.top();pq.pop();
int x=cur.first,y=cur.second;
ord.push_back(idx[{x,y}]);
for(int k=0;k<8;k++){
int nx=x+dx[k],ny=y+dy[k];
if(idx.find({nx,ny}) != idx.end() && !done[{nx,ny}]){
done[{nx,ny}]=1;
pq.push({nx,ny});
}
}
}
if(ord.size() != n){
cout<<"NO\n";exit(0);
}
done.clear();
}
int32_t main(){
cin>>n>>t;
for(int i=1;i<=n;i++){
int x,y;cin>>x>>y;
coord[i]={x,y};
idx[{x,y}]=i;
ss.insert({x,y});
mn=min(mn,make_pair(x,y));
}
test();
while(ord.size()<n){
vector<int>R=boundary(ss);
int mx=0;
for(auto x:R)mx=max(mx,x);
ss.erase(coord[mx]);
ord.push_back(mx);
}
reverse(ord.begin(),ord.end());
cout<<"YES\n";
for(auto x:ord)cout<<x<<"\n";
}
Compilation message
skyscrapers.cpp: In function 'void test()':
skyscrapers.cpp:63:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
63 | if(ord.size() != n){
| ~~~~~~~~~~~^~~~
skyscrapers.cpp: In function 'int32_t main()':
skyscrapers.cpp:78:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
78 | while(ord.size()<n){
| ~~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
348 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
348 KB |
ans=NO N=4 |
4 |
Correct |
0 ms |
348 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
348 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
348 KB |
ans=YES N=5 |
7 |
Correct |
0 ms |
348 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
344 KB |
ans=NO N=10 |
9 |
Incorrect |
1 ms |
348 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
348 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
348 KB |
ans=NO N=4 |
4 |
Correct |
0 ms |
348 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
348 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
348 KB |
ans=YES N=5 |
7 |
Correct |
0 ms |
348 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
344 KB |
ans=NO N=10 |
9 |
Incorrect |
1 ms |
348 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
348 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
348 KB |
ans=NO N=4 |
4 |
Correct |
0 ms |
348 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
348 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
348 KB |
ans=YES N=5 |
7 |
Correct |
0 ms |
348 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
344 KB |
ans=NO N=10 |
9 |
Incorrect |
1 ms |
348 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
ans=NO N=1934 |
2 |
Correct |
2 ms |
604 KB |
ans=NO N=1965 |
3 |
Incorrect |
192 ms |
1088 KB |
Full cells must be connected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
348 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
348 KB |
ans=NO N=4 |
4 |
Correct |
0 ms |
348 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
348 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
348 KB |
ans=YES N=5 |
7 |
Correct |
0 ms |
348 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
344 KB |
ans=NO N=10 |
9 |
Incorrect |
1 ms |
348 KB |
Full cells must be connected |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
18128 KB |
ans=NO N=66151 |
2 |
Correct |
61 ms |
12320 KB |
ans=NO N=64333 |
3 |
Execution timed out |
3598 ms |
25388 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
ans=NO N=1934 |
2 |
Correct |
2 ms |
604 KB |
ans=NO N=1965 |
3 |
Incorrect |
192 ms |
1088 KB |
Full cells must be connected |
4 |
Halted |
0 ms |
0 KB |
- |