# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1108475 | crafticat | Building Skyscrapers (CEOI19_skyscrapers) | C++17 | 758 ms | 1048576 KiB |
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>
using namespace std;
template<typename T>
using V = vector<T>;
using vi = V<int>;
using vb = V<bool>;
using pi = pair<int,int>;
#define F0R(i,n) for (int i = 0; i < n;i++)
#define FOR(i, j, n) for(int i = j; i < n;i++)
#define ckmin(x,y) x = min(x,y)
#define f first
#define s second
vi dx = {0,1,0,-1};
vi dy = {1,0,-1,0};
V<V<V<pi>>> grid;
V<vi> exists;
V<vb> visited;
void dfs(int x, int y) {
visited[x][y] = true;
if (exists[x][y] > 0) return;
for (auto [cX, cY] : grid[x][y]) {
if (visited[cX][cY]) continue;
dfs(cX,cY);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, t; cin >> n >> t;
V<pi> points(n);
int startX = 1e9, startY = 1e9;
F0R(i, n) {
int x, y; cin >> x >> y;
points[i] = {x,y};
ckmin(startX, x);
ckmin(startY, y);
}
startX-=3;
startY-=3;
grid.resize(n + 10, V<V<pi>>(n + 10));
exists.resize(n + 10, vi(n + 10));
visited.resize(n + 10, vb(n + 10));
F0R(i, n) {
points[i].f -= startX;
points[i].s -= startY;
if (points[i].f >= n + 7 || points[i].s >= n + 7) {
cout << "NO\n";
return 0;
}
exists[points[i].f][points[i].s] = i + 1;
}
FOR(i, 1, grid.size() - 1) {
FOR(j, 1, grid[i].size() - 1) {
F0R(k, 4) {
grid[i][j].push_back({i + dx[k], j + dy[k]});
}
}
}
dfs(n + 7, n + 7);
F0R(i, n) {
if (!visited[points[i].f][points[i].s]) {
exit(5);
cout << "NO\n";
return 0;
}
}
priority_queue<int, vi, greater<>> pq;
vb vis(n + 1);
pq.emplace(1);
vi ans;
while (!pq.empty()) {
auto i = pq.top(); pq.pop();
if (vis[i]) continue;
vis[i] = true;
ans.push_back(i);
for (int delX = -1; delX < 2; delX++) {
for (int delY = -1; delY < 2; ++delY) {
int id = exists[points[i - 1].f + delX][points[i - 1].s + delY];
if (id == 0) continue;
if (vis[id]) continue;
pq.emplace(id);
}
}
}
if (ans.size() != n) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
for (auto x : ans)
cout << x << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |