#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include"bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991
const int maxn = 150001;
const int dx[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};
//
const int roundx[] = {1, 1, 0, -1, -1, -1, 0, 1, 1};
const int roundy[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
struct cell {int x, y, id;};
int n, t, ID = 0, buf;
int x[maxn], y[maxn];
cell cells[maxn];
int dsu[4 * maxn];
vector<pair<int,int>> vec[4 * maxn];
bool out[4 * maxn];
map<int,map<int,int>> Empty, Full; // maps cell to dsu
set<cell> active, expendable;
bool operator < (const cell& a, const cell& b) {
return a.id > b.id;
}
int Find (int x) {
return dsu[x] == x ? x : dsu[x] = Find(dsu[x]);
}
void check (const cell &c) {
auto [u, v, id] = c;
int prev = -1, pu, pv;
bool artic = 0, sep = 0;
for (int w = 0 ; w < 9 ; w++) {
int d = (w == 8 ? 0 : w);
int u2 = u + roundx[d];
int v2 = v + roundy[d];
if (Full[u2].count(v2)) sep = 1;
else {
if (d & 1) {
continue;
}
int cmp = Find(Empty[u2][v2]);
if (cmp == prev and sep == 1) {
bool bad = 0;
for (int ww = w + 1 ; ; ww++) {
int d2 = ww % 8;
int u3 = u + roundx[d2];
int v3 = v + roundy[d2];
if (u3 == pu and v3 == pv) {
break;
}
else {
if (Full[u3].count(v3)) {
bad = 1;
break;
}
}
}
if (bad) artic = 1;
}
pu = u2, pv = v2;
sep = 0;
prev = cmp;
}
}
bool isout = 0;
if (!artic) {
for (int d = 0 ; d < 4 ; d++) {
int u2 = u + dx[d];
int v2 = v + dy[d];
if (Empty[u2].count(v2)) {
int cmp = Find(Empty[u2][v2]);
if (out[cmp]) isout = 1;
}
}
}
if (isout and !artic) expendable.insert(c);
else expendable.erase(c);
}
void Union (int a, int b) {
int x = Find(a), y = Find(b);
if (vec[x].size() < vec[y].size()) {
out[y] |= out[x];
for (auto [u, v] : vec[x]) {
vec[y].push_back({u, v});
for (int d = 0 ; d < 8 ; d++) {
if (Full[u + dx[d]].count(v + dy[d])) check(cells[Full[u + dx[d]][v + dy[d]]]);
}
}
dsu[x] = y;
vec[x].clear();
} else {
out[x] |= out[y];
for (auto [u, v] : vec[y]) {
vec[x].push_back({u, v});
for (int d = 0 ; d < 8 ; d++) {
if (Full[u + dx[d]].count(v + dy[d])) check(cells[Full[u + dx[d]][v + dy[d]]]);
}
}
dsu[y] = x;
vec[y].clear();
}
}
signed main () {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> t;
for (int i = 0 ; i < n ; i++) {
cin >> x[i] >> y[i];
cells[i] = {x[i], y[i], i};
Full[x[i]][y[i]] = i;
active.insert(cells[i]);
}
if (n > 1) {
for (int i = 0 ; i < n ; i++) {
bool good = 0;
for (int d = 0 ; d < 8 ; d++) {
int u = x[i] + dx[d];
int v = y[i] + dy[d];
good |= Full[u].count(v);
}
if (!good) {
cout << "NO\n";
return 0;
}
}
}
/* set at leat one node as out (for reference) */ {
pair<int,int> mn = {x[0], y[0]};
for (int i = 0 ; i < n ; i++) {
mn = min(mn, {x[i], y[i]});
}
auto [u, v] = mn; u--;
int id = Empty[u][v] = ID++;
dsu[id] = id;
vec[id].push_back({u, v});
out[id] = 1;
}
for (int i = 0 ; i < n ; i++) {
for (int d = 0 ; d < 8 ; d++) {
int u = x[i] + dx[d];
int v = y[i] + dy[d];
if (!Full[u].count(v) and !Empty[u].count(v)) {
int id = Empty[u][v] = ID++;
dsu[id] = id;
vec[id].push_back({u, v});
}
}
}
for (int i = 0 ; i < n ; i++) {
for (int d = 0 ; d < 8 ; d++) {
int u = x[i] + dx[d];
int v = y[i] + dy[d];
if (!Full[u].count(v)) {
for (int d2 = 0 ; d2 < 4 ; d2++) {
int u2 = u + dx[d2];
int v2 = v + dy[d2];
if (Empty[u2].count(v2)) {
Union(Empty[u][v], Empty[u2][v2]);
}
}
}
}
}
for (int i = 0 ; i < n ; i++) check(cells[i]);
cout << "YES\n";
vector<int> ans;
while (expendable.size()) {
auto [a, b, c] = *expendable.begin();
expendable.erase(expendable.begin());
ans.push_back(c + 1);
Full[a].erase(b);
int id = Empty[a][b] = ID++;
dsu[id] = id;
vec[id].push_back({a, b});
for (int d = 0 ; d < 4 ; d++) {
int u = a + dx[d];
int v = b + dy[d];
if (!Full[u].count(v) and !Empty[u].count(v)) {
int id = Empty[u][v] = ID++;
dsu[id] = id;
vec[id].push_back({u, v});
}
if (Empty[u].count(v)) {
Union(Empty[u][v], id);
}
}
for (int d = 0 ; d < 8 ; d++) {
int u = a + dx[d];
int v = b + dy[d];
if (Full[u].count(v)) check(cells[Full[u][v]]);
}
}
reverse(ans.begin(), ans.end());
for (int i : ans) cout << i << "\n";
}
Compilation message
skyscrapers.cpp:17:1: warning: multi-line comment [-Wcomment]
17 | //\
| ^
skyscrapers.cpp: In function 'void check(const cell&)':
skyscrapers.cpp:66:34: warning: 'pv' may be used uninitialized in this function [-Wmaybe-uninitialized]
66 | if (u3 == pu and v3 == pv) {
| ~~~~~~~~~^~~~~~~~~~~~
skyscrapers.cpp:66:21: warning: 'pu' may be used uninitialized in this function [-Wmaybe-uninitialized]
66 | if (u3 == pu and v3 == pv) {
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14348 KB |
ans=YES N=1 |
2 |
Correct |
8 ms |
14420 KB |
ans=YES N=4 |
3 |
Correct |
9 ms |
14420 KB |
ans=NO N=4 |
4 |
Correct |
9 ms |
14388 KB |
ans=YES N=5 |
5 |
Correct |
9 ms |
14420 KB |
ans=YES N=9 |
6 |
Correct |
8 ms |
14420 KB |
ans=YES N=5 |
7 |
Correct |
9 ms |
14420 KB |
ans=NO N=9 |
8 |
Correct |
9 ms |
14420 KB |
ans=NO N=10 |
9 |
Correct |
9 ms |
14448 KB |
ans=YES N=10 |
10 |
Correct |
11 ms |
14420 KB |
ans=YES N=10 |
11 |
Correct |
9 ms |
14448 KB |
ans=YES N=10 |
12 |
Correct |
10 ms |
14420 KB |
ans=YES N=9 |
13 |
Correct |
9 ms |
14420 KB |
ans=YES N=9 |
14 |
Correct |
9 ms |
14344 KB |
ans=YES N=8 |
15 |
Correct |
8 ms |
14420 KB |
ans=YES N=8 |
16 |
Correct |
8 ms |
14420 KB |
ans=NO N=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14348 KB |
ans=YES N=1 |
2 |
Correct |
8 ms |
14420 KB |
ans=YES N=4 |
3 |
Correct |
9 ms |
14420 KB |
ans=NO N=4 |
4 |
Correct |
9 ms |
14388 KB |
ans=YES N=5 |
5 |
Correct |
9 ms |
14420 KB |
ans=YES N=9 |
6 |
Correct |
8 ms |
14420 KB |
ans=YES N=5 |
7 |
Correct |
9 ms |
14420 KB |
ans=NO N=9 |
8 |
Correct |
9 ms |
14420 KB |
ans=NO N=10 |
9 |
Correct |
9 ms |
14448 KB |
ans=YES N=10 |
10 |
Correct |
11 ms |
14420 KB |
ans=YES N=10 |
11 |
Correct |
9 ms |
14448 KB |
ans=YES N=10 |
12 |
Correct |
10 ms |
14420 KB |
ans=YES N=9 |
13 |
Correct |
9 ms |
14420 KB |
ans=YES N=9 |
14 |
Correct |
9 ms |
14344 KB |
ans=YES N=8 |
15 |
Correct |
8 ms |
14420 KB |
ans=YES N=8 |
16 |
Correct |
8 ms |
14420 KB |
ans=NO N=2 |
17 |
Correct |
8 ms |
14420 KB |
ans=YES N=17 |
18 |
Incorrect |
9 ms |
14420 KB |
Full cells must be connected |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14348 KB |
ans=YES N=1 |
2 |
Correct |
8 ms |
14420 KB |
ans=YES N=4 |
3 |
Correct |
9 ms |
14420 KB |
ans=NO N=4 |
4 |
Correct |
9 ms |
14388 KB |
ans=YES N=5 |
5 |
Correct |
9 ms |
14420 KB |
ans=YES N=9 |
6 |
Correct |
8 ms |
14420 KB |
ans=YES N=5 |
7 |
Correct |
9 ms |
14420 KB |
ans=NO N=9 |
8 |
Correct |
9 ms |
14420 KB |
ans=NO N=10 |
9 |
Correct |
9 ms |
14448 KB |
ans=YES N=10 |
10 |
Correct |
11 ms |
14420 KB |
ans=YES N=10 |
11 |
Correct |
9 ms |
14448 KB |
ans=YES N=10 |
12 |
Correct |
10 ms |
14420 KB |
ans=YES N=9 |
13 |
Correct |
9 ms |
14420 KB |
ans=YES N=9 |
14 |
Correct |
9 ms |
14344 KB |
ans=YES N=8 |
15 |
Correct |
8 ms |
14420 KB |
ans=YES N=8 |
16 |
Correct |
8 ms |
14420 KB |
ans=NO N=2 |
17 |
Correct |
8 ms |
14420 KB |
ans=YES N=17 |
18 |
Incorrect |
9 ms |
14420 KB |
Full cells must be connected |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14932 KB |
ans=NO N=1934 |
2 |
Correct |
10 ms |
14676 KB |
ans=NO N=1965 |
3 |
Incorrect |
42 ms |
14920 KB |
Contestant's solution is not lexicographically largest at index 1814 (1712 vs 1702) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14348 KB |
ans=YES N=1 |
2 |
Correct |
8 ms |
14420 KB |
ans=YES N=4 |
3 |
Correct |
9 ms |
14420 KB |
ans=NO N=4 |
4 |
Correct |
9 ms |
14388 KB |
ans=YES N=5 |
5 |
Correct |
9 ms |
14420 KB |
ans=YES N=9 |
6 |
Correct |
8 ms |
14420 KB |
ans=YES N=5 |
7 |
Correct |
9 ms |
14420 KB |
ans=NO N=9 |
8 |
Correct |
9 ms |
14420 KB |
ans=NO N=10 |
9 |
Correct |
9 ms |
14448 KB |
ans=YES N=10 |
10 |
Correct |
11 ms |
14420 KB |
ans=YES N=10 |
11 |
Correct |
9 ms |
14448 KB |
ans=YES N=10 |
12 |
Correct |
10 ms |
14420 KB |
ans=YES N=9 |
13 |
Correct |
9 ms |
14420 KB |
ans=YES N=9 |
14 |
Correct |
9 ms |
14344 KB |
ans=YES N=8 |
15 |
Correct |
8 ms |
14420 KB |
ans=YES N=8 |
16 |
Correct |
8 ms |
14420 KB |
ans=NO N=2 |
17 |
Correct |
8 ms |
14420 KB |
ans=YES N=17 |
18 |
Incorrect |
9 ms |
14420 KB |
Full cells must be connected |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
25236 KB |
ans=NO N=66151 |
2 |
Correct |
57 ms |
25036 KB |
ans=NO N=64333 |
3 |
Incorrect |
1857 ms |
32016 KB |
Full cells must be connected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14932 KB |
ans=NO N=1934 |
2 |
Correct |
10 ms |
14676 KB |
ans=NO N=1965 |
3 |
Incorrect |
42 ms |
14920 KB |
Contestant's solution is not lexicographically largest at index 1814 (1712 vs 1702) |
4 |
Halted |
0 ms |
0 KB |
- |