#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
int grid[5001][5001],vs[5001][5001],w[5001][5001];
int x[] = {-1,-1,-1,0,1,1,1,0}, y[] = {-1,0,1,1,1,0,-1,-1};
int xx[] = {0,0,1,-1}, yy[] = {1,-1,0,0};
vector<pair<int,int>>p;
vector<pair<int,int>>nxt;
vector<int>ans;
int n;
vector<int>fin[200001];
bool cmp(int* a, int *b){
return *a < *b;
}
bool check(){
vector<pair<int,int>>b;
b.push_back({p[0].first,p[0].second});
set<pair<int,int>>c,d;
for(int i = 1; i < n; i++){
d.insert({p[i].first,p[i].second});
}
int j = 0;
while(j < b.size()){
for(int k = 0; k < 8; k++){
int nx = b[j].first + x[k], ny = b[j].second + y[k];
if(d.count({nx,ny})){
d.erase({nx,ny});
b.push_back({nx,ny});
}
}
j++;
}
return d.empty();
}
void dfs(int a, int b){
vs[a][b] = 1;
if(grid[a][b]){
nxt.push_back({a,b});
return;
}
for(int k = 0; k < 4; k++){
int aa = a + xx[k], bb = b + yy[k];
if(aa < 0 || bb < 0 || aa >= 2 * n || bb >= 2 * n || vs[aa][bb]) continue;
dfs(aa,bb);
}
}
signed main(){
boost;
int t, cnt = 0; cin >> n >> t;
vector<int*>d;
set<int>tt; map<int,int>bb;
for(int i = 0; i < n; i++){
int x,y;
cin >> x >> y;
p.push_back({x,y});
tt.insert(x); tt.insert(y);
}
if(!check()){
cout << "NO";
return 0;
}
for(auto s:tt){
bb[s] = cnt++;
}
for(int i = 0; i < n; i++){
p[i].first = bb[p[i].first];
p[i].second = bb[p[i].second];
grid[p[i].first][p[i].second] = 1;
w[p[i].first][p[i].second] = i;
}
for(int i = 0; i < 2 * n; i++){
for(int j = 0; j < 2 * n; j++){
if(i == 0 || j == 0 || i == 2 * n - 1 || j == 2 * n - 1){
if(!vs[i][j]){
dfs(i,j);
}
}
}
}
int cc = 0;
while(nxt.size()){
vector<pair<int,int>>b;
set<pair<int,int>>s;
b.push_back({nxt[0].first,nxt[0].second});
fin[cc].push_back(w[nxt[0].first][nxt[0].second]);
for(int i = 1; i < nxt.size(); i++){
s.insert({nxt[i].first,nxt[i].second});
}
int j = 0;
while(j < b.size()){
for(int k = 0; k < 8; k++){
int nx = b[j].first + x[k], ny = b[j].second + y[k];
if(s.count({nx,ny})){
s.erase({nx,ny});
b.push_back({nx,ny});
fin[cc].push_back(w[nx][ny]);
}
}
j++;
}
nxt.clear();
int f = -1;
for(int i = 0; i < b.size(); i++){
for(int k = 0; k < 4; k++){
int aa = b[i].first + xx[k], bb = b[i].second + yy[k];
if(aa < 0 || bb < 0 || aa >= 2 * n || bb >= 2 * n || vs[aa][bb]) continue;
if(grid[aa][bb]) {
f = w[b[i].first][b[i].second];
dfs(aa,bb);
break;
}
}
if(f != -1) break;
}
for(int i = 1; i < fin[cc].size(); i++){
if(fin[cc][i] == f){
swap(fin[cc][0],fin[cc][i]);
}
}
for(int i = 0; i < b.size(); i++){
for(int k = 0; k < 4; k++){
int aa = b[i].first + xx[k], bb = b[i].second + yy[k];
if(aa < 0 || bb < 0 || aa >= 2 * n || bb >= 2 * n || vs[aa][bb]) continue;
dfs(aa,bb);
}
}
cc++;
}
cout << "YES" << endl;
for(int i = cc - 1; i >= 0; i--){
for(int j = 0; j < fin[i].size(); j++){
cout << fin[i][j] + 1 << endl;
}
}
return 0;
}
Compilation message
skyscrapers.cpp: In function 'bool check()':
skyscrapers.cpp:36:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | while(j < b.size()){
| ~~^~~~~~~~~~
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:106:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int i = 1; i < nxt.size(); i++){
| ~~^~~~~~~~~~~~
skyscrapers.cpp:110:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | while(j < b.size()){
| ~~^~~~~~~~~~
skyscrapers.cpp:123:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for(int i = 0; i < b.size(); i++){
| ~~^~~~~~~~~~
skyscrapers.cpp:135:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for(int i = 1; i < fin[cc].size(); i++){
| ~~^~~~~~~~~~~~~~~~
skyscrapers.cpp:140:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | for(int i = 0; i < b.size(); i++){
| ~~^~~~~~~~~~
skyscrapers.cpp:151:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
151 | for(int j = 0; j < fin[i].size(); j++){
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
ans=YES N=1 |
2 |
Correct |
3 ms |
5076 KB |
ans=YES N=4 |
3 |
Correct |
3 ms |
4948 KB |
ans=NO N=4 |
4 |
Correct |
3 ms |
5076 KB |
ans=YES N=5 |
5 |
Correct |
3 ms |
5076 KB |
ans=YES N=9 |
6 |
Correct |
2 ms |
5076 KB |
ans=YES N=5 |
7 |
Correct |
2 ms |
4948 KB |
ans=NO N=9 |
8 |
Correct |
3 ms |
4948 KB |
ans=NO N=10 |
9 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
10 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
11 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
12 |
Correct |
3 ms |
5076 KB |
ans=YES N=9 |
13 |
Correct |
2 ms |
5076 KB |
ans=YES N=9 |
14 |
Correct |
3 ms |
5076 KB |
ans=YES N=8 |
15 |
Correct |
3 ms |
5076 KB |
ans=YES N=8 |
16 |
Correct |
3 ms |
4948 KB |
ans=NO N=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
ans=YES N=1 |
2 |
Correct |
3 ms |
5076 KB |
ans=YES N=4 |
3 |
Correct |
3 ms |
4948 KB |
ans=NO N=4 |
4 |
Correct |
3 ms |
5076 KB |
ans=YES N=5 |
5 |
Correct |
3 ms |
5076 KB |
ans=YES N=9 |
6 |
Correct |
2 ms |
5076 KB |
ans=YES N=5 |
7 |
Correct |
2 ms |
4948 KB |
ans=NO N=9 |
8 |
Correct |
3 ms |
4948 KB |
ans=NO N=10 |
9 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
10 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
11 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
12 |
Correct |
3 ms |
5076 KB |
ans=YES N=9 |
13 |
Correct |
2 ms |
5076 KB |
ans=YES N=9 |
14 |
Correct |
3 ms |
5076 KB |
ans=YES N=8 |
15 |
Correct |
3 ms |
5076 KB |
ans=YES N=8 |
16 |
Correct |
3 ms |
4948 KB |
ans=NO N=2 |
17 |
Correct |
2 ms |
5324 KB |
ans=YES N=17 |
18 |
Incorrect |
3 ms |
5460 KB |
Full cells must be connected |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
ans=YES N=1 |
2 |
Correct |
3 ms |
5076 KB |
ans=YES N=4 |
3 |
Correct |
3 ms |
4948 KB |
ans=NO N=4 |
4 |
Correct |
3 ms |
5076 KB |
ans=YES N=5 |
5 |
Correct |
3 ms |
5076 KB |
ans=YES N=9 |
6 |
Correct |
2 ms |
5076 KB |
ans=YES N=5 |
7 |
Correct |
2 ms |
4948 KB |
ans=NO N=9 |
8 |
Correct |
3 ms |
4948 KB |
ans=NO N=10 |
9 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
10 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
11 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
12 |
Correct |
3 ms |
5076 KB |
ans=YES N=9 |
13 |
Correct |
2 ms |
5076 KB |
ans=YES N=9 |
14 |
Correct |
3 ms |
5076 KB |
ans=YES N=8 |
15 |
Correct |
3 ms |
5076 KB |
ans=YES N=8 |
16 |
Correct |
3 ms |
4948 KB |
ans=NO N=2 |
17 |
Correct |
2 ms |
5324 KB |
ans=YES N=17 |
18 |
Incorrect |
3 ms |
5460 KB |
Full cells must be connected |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5332 KB |
ans=NO N=1934 |
2 |
Correct |
4 ms |
5120 KB |
ans=NO N=1965 |
3 |
Runtime error |
460 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
ans=YES N=1 |
2 |
Correct |
3 ms |
5076 KB |
ans=YES N=4 |
3 |
Correct |
3 ms |
4948 KB |
ans=NO N=4 |
4 |
Correct |
3 ms |
5076 KB |
ans=YES N=5 |
5 |
Correct |
3 ms |
5076 KB |
ans=YES N=9 |
6 |
Correct |
2 ms |
5076 KB |
ans=YES N=5 |
7 |
Correct |
2 ms |
4948 KB |
ans=NO N=9 |
8 |
Correct |
3 ms |
4948 KB |
ans=NO N=10 |
9 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
10 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
11 |
Correct |
3 ms |
5076 KB |
ans=YES N=10 |
12 |
Correct |
3 ms |
5076 KB |
ans=YES N=9 |
13 |
Correct |
2 ms |
5076 KB |
ans=YES N=9 |
14 |
Correct |
3 ms |
5076 KB |
ans=YES N=8 |
15 |
Correct |
3 ms |
5076 KB |
ans=YES N=8 |
16 |
Correct |
3 ms |
4948 KB |
ans=NO N=2 |
17 |
Correct |
2 ms |
5324 KB |
ans=YES N=17 |
18 |
Incorrect |
3 ms |
5460 KB |
Full cells must be connected |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
13252 KB |
ans=NO N=66151 |
2 |
Correct |
37 ms |
10064 KB |
ans=NO N=64333 |
3 |
Runtime error |
564 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5332 KB |
ans=NO N=1934 |
2 |
Correct |
4 ms |
5120 KB |
ans=NO N=1965 |
3 |
Runtime error |
460 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |