#include <bits/stdc++.h>
using namespace std;
int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, t; cin >> n >> t;
vector<array<int, 2>> points;
set<int> points_set;
map<array<int, 2>, int> pt_to_idx;
for (int i = 0; i < n; i++){
int x, y; cin >> x >> y;
points.push_back({x, y});
points_set.insert(i);
pt_to_idx[{x, y}] = i;
}
queue<int> bfs;
bfs.push(pt_to_idx.begin()->second);
set<array<int, 2>> visited;
visited.insert({points[bfs.front()][0], points[bfs.front()][1]});
vector<int> ans;
while (!bfs.empty()){
int tp = bfs.front(); bfs.pop();
ans.push_back(tp);
for (int d = 0; d < 8; d++){
array<int, 2> new_pt = {points[tp][0] + dx[d], points[tp][1] + dy[d]};
if (!visited.count(new_pt)){
if (pt_to_idx.count(new_pt)){
visited.insert(new_pt);
bfs.push(pt_to_idx[new_pt]);
}
}
}
}
if (ans.size() != n){
cout << "NO\n";
return 0;
}
cout << "YES\n";
for (int i = 0; i < n; i++){
cout << ans[i] + 1 << "\n";
}
// if (ans.size() == n){
// cerr << "hi\n";
// set<array<int, 2>> curr_cells;
// for (int i = 0; i < n; i++){
// array<int, 2> cp = points[ans[i]];
// assert(!curr_cells.count({cp[0], cp[1]+1}) || !curr_cells.count({cp[0], cp[1]-1}) || !curr_cells.count({cp[0]+1, cp[1]}) || !curr_cells.count({cp[0]-1, cp[1]}));
// curr_cells.insert(cp);
// }
// }
}
Compilation message
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:40:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if (ans.size() != n){
| ~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
212 KB |
ans=YES N=5 |
7 |
Correct |
0 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
1 ms |
320 KB |
ans=NO N=10 |
9 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
10 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
11 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
12 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
13 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
14 |
Correct |
1 ms |
316 KB |
ans=YES N=8 |
15 |
Correct |
0 ms |
320 KB |
ans=YES N=8 |
16 |
Correct |
0 ms |
212 KB |
ans=NO N=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
212 KB |
ans=YES N=5 |
7 |
Correct |
0 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
1 ms |
320 KB |
ans=NO N=10 |
9 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
10 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
11 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
12 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
13 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
14 |
Correct |
1 ms |
316 KB |
ans=YES N=8 |
15 |
Correct |
0 ms |
320 KB |
ans=YES N=8 |
16 |
Correct |
0 ms |
212 KB |
ans=NO N=2 |
17 |
Correct |
0 ms |
212 KB |
ans=YES N=17 |
18 |
Incorrect |
1 ms |
212 KB |
Added cell 25 (1,-1) not reachable from infinity |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
212 KB |
ans=YES N=5 |
7 |
Correct |
0 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
1 ms |
320 KB |
ans=NO N=10 |
9 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
10 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
11 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
12 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
13 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
14 |
Correct |
1 ms |
316 KB |
ans=YES N=8 |
15 |
Correct |
0 ms |
320 KB |
ans=YES N=8 |
16 |
Correct |
0 ms |
212 KB |
ans=NO N=2 |
17 |
Correct |
0 ms |
212 KB |
ans=YES N=17 |
18 |
Incorrect |
1 ms |
212 KB |
Added cell 25 (1,-1) not reachable from infinity |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
ans=NO N=1934 |
2 |
Correct |
1 ms |
468 KB |
ans=NO N=1965 |
3 |
Incorrect |
3 ms |
596 KB |
Contestant's solution is not lexicographically largest at index 1824 (1813 vs 1702) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
212 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
212 KB |
ans=NO N=4 |
4 |
Correct |
1 ms |
212 KB |
ans=YES N=5 |
5 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
6 |
Correct |
0 ms |
212 KB |
ans=YES N=5 |
7 |
Correct |
0 ms |
212 KB |
ans=NO N=9 |
8 |
Correct |
1 ms |
320 KB |
ans=NO N=10 |
9 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
10 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
11 |
Correct |
0 ms |
212 KB |
ans=YES N=10 |
12 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
13 |
Correct |
0 ms |
212 KB |
ans=YES N=9 |
14 |
Correct |
1 ms |
316 KB |
ans=YES N=8 |
15 |
Correct |
0 ms |
320 KB |
ans=YES N=8 |
16 |
Correct |
0 ms |
212 KB |
ans=NO N=2 |
17 |
Correct |
0 ms |
212 KB |
ans=YES N=17 |
18 |
Incorrect |
1 ms |
212 KB |
Added cell 25 (1,-1) not reachable from infinity |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
12084 KB |
ans=NO N=66151 |
2 |
Correct |
36 ms |
8380 KB |
ans=NO N=64333 |
3 |
Incorrect |
118 ms |
12920 KB |
Contestant's solution is not lexicographically largest at index 69316 (69235 vs 13970) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
ans=NO N=1934 |
2 |
Correct |
1 ms |
468 KB |
ans=NO N=1965 |
3 |
Incorrect |
3 ms |
596 KB |
Contestant's solution is not lexicographically largest at index 1824 (1813 vs 1702) |
4 |
Halted |
0 ms |
0 KB |
- |