#include <bits/stdc++.h>
using namespace std;
const int N = 150'000 + 10,
dx[8] = {-1, 1, 1, 0, -1},
dy[8] = {0, 0, 1, 1, 1};
int n, type;
struct Point {
int r, c, idx;
bool operator > (const auto& rhs) {
return make_pair(r, c) > make_pair(rhs.r, rhs.c);
}
friend ostream& operator << (ostream& os, const auto& rhs) {
return os << rhs.r << " " << rhs.c << " " << rhs.idx;
}
} p[N];
unordered_map<int, unordered_map<int, int>> rvs;
bool mk[N];
vector<int> answer;
void dfs(int idx) {
int r = p[idx].r, c = p[idx].c;
answer.push_back(idx);
for (int i = 0; i < 5; ++i) {
int nR = r + dx[i], nC = c + dy[i],
nxt = rvs[nR][nC];
if (!nxt || mk[nxt]) continue;
mk[nxt] = true;
dfs(nxt);
if (i >= 2) break;
}
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> type;
for (int i = 1; i <= n; ++i) {
int r, c; cin >> r >> c;
p[i] = {r, c, i};
rvs[r][c] = i;
}
Point st = p[1];
for (int i = 1; i <= n; ++i) if (st > p[i]) st = p[i];
mk[st.idx] = true;
dfs(st.idx);
if (answer.size() != n) { cout << "No\n"; return 0; };
cout << "YES\n";
for (const auto& x : answer) cout << x << "\n";
}
Compilation message
skyscrapers.cpp:12:25: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
12 | bool operator > (const auto& rhs) {
| ^~~~
skyscrapers.cpp:15:50: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
15 | friend ostream& operator << (ostream& os, const auto& rhs) {
| ^~~~
skyscrapers.cpp: In function 'int32_t main()':
skyscrapers.cpp:52:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
52 | if (answer.size() != n) { cout << "No\n"; return 0; };
| ~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
ans=YES N=1 |
2 |
Correct |
1 ms |
348 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
348 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
348 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
ans=YES N=1 |
2 |
Correct |
1 ms |
348 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
348 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
348 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
ans=YES N=1 |
2 |
Correct |
1 ms |
348 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
348 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
348 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
860 KB |
ans=NO N=1934 |
2 |
Correct |
1 ms |
348 KB |
ans=NO N=1965 |
3 |
Incorrect |
1 ms |
604 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
ans=YES N=1 |
2 |
Correct |
1 ms |
348 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
348 KB |
ans=NO N=4 |
4 |
Incorrect |
0 ms |
348 KB |
Contestant did not find solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
5592 KB |
ans=NO N=66151 |
2 |
Correct |
17 ms |
4172 KB |
ans=NO N=64333 |
3 |
Incorrect |
28 ms |
6724 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
860 KB |
ans=NO N=1934 |
2 |
Correct |
1 ms |
348 KB |
ans=NO N=1965 |
3 |
Incorrect |
1 ms |
604 KB |
Contestant did not find solution |
4 |
Halted |
0 ms |
0 KB |
- |