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>
struct Point {
int r, c;
};
auto compPoint = [](Point a, Point b) {
return std::make_pair(a.r, a.c) < std::make_pair(b.r, b.c);
};
std::pair<int, int> dxy[8] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};
int main() {
int N, T;
std::cin >> N >> T;
std::vector<Point> sks(N);
for (auto &[r, c] : sks) {
std::cin >> r >> c;
}
std::map<Point, int, decltype(compPoint)> skMap(compPoint);
for (int i = 0; i < N; ++i) {
skMap[sks[i]] = i;
}
std::vector<bool> isSeen(N);
std::vector<int> answer;
std::priority_queue<Point, std::vector<Point>, decltype(compPoint)> que(compPoint);
int minV = 0;
for (int i = 1; i < N; ++i) {
if (compPoint(sks[i], sks[minV])) {
minV = i;
}
}
que.push(sks[minV]);
isSeen[minV] = true;
while (not que.empty()) {
const auto [r, c] = que.top();
que.pop();
const int f = skMap[{r, c}];
answer.push_back(f);
for (const auto &[ar, ac] : dxy) {
const int nr = r + ar, nc = c + ac;
auto itr = skMap.find({nr, nc});
if (itr == skMap.end()) {
continue;
}
const int t = itr->second;
if (isSeen[t]) {
continue;
}
isSeen[t] = true;
que.push({nr, nc});
}
}
if (answer.size() != N) {
std::cout << "NO" << std::endl;
return 0;
}
std::cout << "YES" << std::endl;
for (const auto e : answer) {
std::cout << e + 1 << std::endl;
}
}
Compilation message (stderr)
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:55:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | if (answer.size() != N) {
| ~~~~~~~~~~~~~~^~~~
# | 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... |