#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
#define X first
#define Y second
int n, t, cnt;
map<ii, int> M;
ii cor[1000007];
int skynum[150007];
int component[1000007];
bool engaged[1000007];
vector<int> incomp[1000007];
vector<int> G4[1000007], G8[1000007];
bool vis[1000007];
int ecnt;
int infty;
void add_point(int x, int y) {
ii p = {x, y};
if(!M.count(p)) {
M[p] = ++cnt;
cor[cnt] = p;
component[cnt] = cnt;
incomp[cnt].push_back(cnt);
}
}
bool check(int i) {
bool eng[3][3];
int comp[3][3];
for(int w : G8[i]) {
int x = cor[w].X - cor[i].X + 1;
int y = cor[w].Y - cor[i].Y + 1;
eng[x][y] = engaged[w];
comp[x][y] = component[w];
}
if(!eng[0][1] && !eng[1][2] && comp[0][1] == comp[1][2] && eng[0][2]
&& (eng[0][0] || eng[1][0] || eng[2][0] || eng[2][1] || eng[2][2]))
return false;
if(!eng[1][2] && !eng[2][1] && comp[1][2] == comp[2][1] && eng[2][2]
&& (eng[2][0] || eng[1][0] || eng[0][0] || eng[0][1] || eng[0][2]))
return false;
if(!eng[2][1] && !eng[1][0] && comp[2][1] == comp[1][0] && eng[2][0]
&& (eng[0][0] || eng[0][1] || eng[0][2] || eng[1][2] || eng[2][2]))
return false;
if(!eng[1][0] && !eng[0][1] && comp[1][0] == comp[1][0] && eng[0][0]
&& (eng[0][2] || eng[1][2] || eng[2][2] || eng[2][1] || eng[2][0]))
return false;
if(!eng[0][1] && !eng[2][1] && comp[0][1] == comp[2][1]
&& (eng[0][0] || eng[1][0] || eng[2][0]) && (eng[0][2] || eng[1][2] || eng[2][2]))
return false;
if(!eng[1][0] && !eng[1][2] && comp[1][0] == comp[1][2]
&& (eng[0][0] || eng[0][1] || eng[0][2]) && (eng[2][0] || eng[2][1] || eng[2][2]))
return false;
if(comp[1][0] == component[infty] || comp[0][1] == component[infty]
|| comp[2][1] == component[infty] || comp[1][2] == component[infty])
return true;
return false;
}
void merge(int a, int b) {
if(a == b)
return ;
if(incomp[b].size() > incomp[a].size())
swap(a, b);
for(int x : incomp[b]) {
incomp[a].push_back(x);
component[x] = a;
}
incomp[b].clear();
}
void erase(int w) {
engaged[w] = 0;
for(int u : G4[w])
if(!engaged[u])
merge(component[w], component[u]);
}
void dfs(int w) {
if(vis[w])
return ;
vis[w] = 1;
ecnt++;
for(int u : G8[w])
if(engaged[u])
dfs(u);
}
int main() {
scanf("%d%d", &n, &t);
ii minp = {1e9 + 7, 1e9 + 7};
for(int i = 1 ; i <= n ; i++) {
int r, c;
scanf("%d%d", &r, &c);
for(int x = -1 ; x <= 1 ; x++)
for(int y = -1 ; y <= 1 ; y++)
add_point(r + x, c + y);
engaged[M[{r, c}]] = 1;
skynum[i] = M[{r, c}];
minp = min(minp, {r, c});
}
infty = M[{minp.X - 1, minp.Y}];
for(int i = 1 ; i <= cnt ; i++) {
int x = cor[i].X;
int y = cor[i].Y;
for(int xo = -1 ; xo <= 1 ; xo++) {
for(int yo = -1 ; yo <= 1 ; yo++) {
ii p2 = {x + xo, y + yo};
if(M.count(p2) == 0)
continue;
int num = M[p2];
if(xo || yo)
G8[i].push_back(num);
if((xo || yo) && !(xo && yo)) {
G4[i].push_back(num);
if(!engaged[i] && !engaged[num])
merge(component[i], component[num]);
}
}
}
}
dfs(skynum[1]);
if(ecnt != n) {
printf("NO\n");
return 0;
}
printf("YES\n");
vector<int> res;
for(int i = 0 ; i < n ; i++) {
for(int j = n ; j >= 1 ; j--) {
if(engaged[skynum[j]] && check(skynum[j])) {
erase(skynum[j]);
res.push_back(j);
break;
}
}
}
reverse(res.begin(), res.end());
for(int x : res)
printf("%d\n", x);
return 0;
}
Compilation message
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &t);
~~~~~^~~~~~~~~~~~~~~~
skyscrapers.cpp:107:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &r, &c);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
70776 KB |
ans=YES N=1 |
2 |
Correct |
44 ms |
70904 KB |
ans=YES N=4 |
3 |
Correct |
45 ms |
70776 KB |
ans=NO N=4 |
4 |
Correct |
44 ms |
70776 KB |
ans=YES N=5 |
5 |
Correct |
45 ms |
70776 KB |
ans=YES N=9 |
6 |
Correct |
45 ms |
70776 KB |
ans=YES N=5 |
7 |
Correct |
46 ms |
70776 KB |
ans=NO N=9 |
8 |
Correct |
45 ms |
70776 KB |
ans=NO N=10 |
9 |
Correct |
47 ms |
70784 KB |
ans=YES N=10 |
10 |
Correct |
44 ms |
70784 KB |
ans=YES N=10 |
11 |
Correct |
46 ms |
70776 KB |
ans=YES N=10 |
12 |
Correct |
45 ms |
70776 KB |
ans=YES N=9 |
13 |
Correct |
44 ms |
70784 KB |
ans=YES N=9 |
14 |
Correct |
44 ms |
70776 KB |
ans=YES N=8 |
15 |
Correct |
46 ms |
70832 KB |
ans=YES N=8 |
16 |
Correct |
44 ms |
70784 KB |
ans=NO N=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
70776 KB |
ans=YES N=1 |
2 |
Correct |
44 ms |
70904 KB |
ans=YES N=4 |
3 |
Correct |
45 ms |
70776 KB |
ans=NO N=4 |
4 |
Correct |
44 ms |
70776 KB |
ans=YES N=5 |
5 |
Correct |
45 ms |
70776 KB |
ans=YES N=9 |
6 |
Correct |
45 ms |
70776 KB |
ans=YES N=5 |
7 |
Correct |
46 ms |
70776 KB |
ans=NO N=9 |
8 |
Correct |
45 ms |
70776 KB |
ans=NO N=10 |
9 |
Correct |
47 ms |
70784 KB |
ans=YES N=10 |
10 |
Correct |
44 ms |
70784 KB |
ans=YES N=10 |
11 |
Correct |
46 ms |
70776 KB |
ans=YES N=10 |
12 |
Correct |
45 ms |
70776 KB |
ans=YES N=9 |
13 |
Correct |
44 ms |
70784 KB |
ans=YES N=9 |
14 |
Correct |
44 ms |
70776 KB |
ans=YES N=8 |
15 |
Correct |
46 ms |
70832 KB |
ans=YES N=8 |
16 |
Correct |
44 ms |
70784 KB |
ans=NO N=2 |
17 |
Correct |
43 ms |
70780 KB |
ans=YES N=17 |
18 |
Correct |
44 ms |
70776 KB |
ans=YES N=25 |
19 |
Correct |
48 ms |
70780 KB |
ans=YES N=100 |
20 |
Correct |
45 ms |
70904 KB |
ans=YES N=185 |
21 |
Correct |
48 ms |
71168 KB |
ans=NO N=174 |
22 |
Correct |
46 ms |
70776 KB |
ans=YES N=90 |
23 |
Correct |
52 ms |
70796 KB |
ans=YES N=63 |
24 |
Correct |
45 ms |
70904 KB |
ans=YES N=87 |
25 |
Correct |
47 ms |
70776 KB |
ans=YES N=183 |
26 |
Correct |
48 ms |
70904 KB |
ans=YES N=188 |
27 |
Correct |
47 ms |
70904 KB |
ans=YES N=183 |
28 |
Correct |
45 ms |
70904 KB |
ans=YES N=189 |
29 |
Correct |
46 ms |
70912 KB |
ans=YES N=200 |
30 |
Correct |
48 ms |
70904 KB |
ans=YES N=190 |
31 |
Correct |
46 ms |
70912 KB |
ans=YES N=187 |
32 |
Correct |
45 ms |
70904 KB |
ans=YES N=187 |
33 |
Correct |
47 ms |
71040 KB |
ans=YES N=182 |
34 |
Correct |
51 ms |
70904 KB |
ans=YES N=184 |
35 |
Correct |
45 ms |
70904 KB |
ans=YES N=188 |
36 |
Correct |
47 ms |
70904 KB |
ans=YES N=181 |
37 |
Correct |
46 ms |
70908 KB |
ans=YES N=188 |
38 |
Correct |
46 ms |
70904 KB |
ans=YES N=191 |
39 |
Correct |
45 ms |
70824 KB |
ans=YES N=196 |
40 |
Correct |
46 ms |
70904 KB |
ans=YES N=196 |
41 |
Correct |
45 ms |
70892 KB |
ans=YES N=196 |
42 |
Correct |
45 ms |
70904 KB |
ans=YES N=196 |
43 |
Correct |
45 ms |
70904 KB |
ans=YES N=195 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
70776 KB |
ans=YES N=1 |
2 |
Correct |
44 ms |
70904 KB |
ans=YES N=4 |
3 |
Correct |
45 ms |
70776 KB |
ans=NO N=4 |
4 |
Correct |
44 ms |
70776 KB |
ans=YES N=5 |
5 |
Correct |
45 ms |
70776 KB |
ans=YES N=9 |
6 |
Correct |
45 ms |
70776 KB |
ans=YES N=5 |
7 |
Correct |
46 ms |
70776 KB |
ans=NO N=9 |
8 |
Correct |
45 ms |
70776 KB |
ans=NO N=10 |
9 |
Correct |
47 ms |
70784 KB |
ans=YES N=10 |
10 |
Correct |
44 ms |
70784 KB |
ans=YES N=10 |
11 |
Correct |
46 ms |
70776 KB |
ans=YES N=10 |
12 |
Correct |
45 ms |
70776 KB |
ans=YES N=9 |
13 |
Correct |
44 ms |
70784 KB |
ans=YES N=9 |
14 |
Correct |
44 ms |
70776 KB |
ans=YES N=8 |
15 |
Correct |
46 ms |
70832 KB |
ans=YES N=8 |
16 |
Correct |
44 ms |
70784 KB |
ans=NO N=2 |
17 |
Correct |
43 ms |
70780 KB |
ans=YES N=17 |
18 |
Correct |
44 ms |
70776 KB |
ans=YES N=25 |
19 |
Correct |
48 ms |
70780 KB |
ans=YES N=100 |
20 |
Correct |
45 ms |
70904 KB |
ans=YES N=185 |
21 |
Correct |
48 ms |
71168 KB |
ans=NO N=174 |
22 |
Correct |
46 ms |
70776 KB |
ans=YES N=90 |
23 |
Correct |
52 ms |
70796 KB |
ans=YES N=63 |
24 |
Correct |
45 ms |
70904 KB |
ans=YES N=87 |
25 |
Correct |
47 ms |
70776 KB |
ans=YES N=183 |
26 |
Correct |
48 ms |
70904 KB |
ans=YES N=188 |
27 |
Correct |
47 ms |
70904 KB |
ans=YES N=183 |
28 |
Correct |
45 ms |
70904 KB |
ans=YES N=189 |
29 |
Correct |
46 ms |
70912 KB |
ans=YES N=200 |
30 |
Correct |
48 ms |
70904 KB |
ans=YES N=190 |
31 |
Correct |
46 ms |
70912 KB |
ans=YES N=187 |
32 |
Correct |
45 ms |
70904 KB |
ans=YES N=187 |
33 |
Correct |
47 ms |
71040 KB |
ans=YES N=182 |
34 |
Correct |
51 ms |
70904 KB |
ans=YES N=184 |
35 |
Correct |
45 ms |
70904 KB |
ans=YES N=188 |
36 |
Correct |
47 ms |
70904 KB |
ans=YES N=181 |
37 |
Correct |
46 ms |
70908 KB |
ans=YES N=188 |
38 |
Correct |
46 ms |
70904 KB |
ans=YES N=191 |
39 |
Correct |
45 ms |
70824 KB |
ans=YES N=196 |
40 |
Correct |
46 ms |
70904 KB |
ans=YES N=196 |
41 |
Correct |
45 ms |
70892 KB |
ans=YES N=196 |
42 |
Correct |
45 ms |
70904 KB |
ans=YES N=196 |
43 |
Correct |
45 ms |
70904 KB |
ans=YES N=195 |
44 |
Correct |
77 ms |
73976 KB |
ans=NO N=1934 |
45 |
Correct |
60 ms |
71928 KB |
ans=NO N=1965 |
46 |
Correct |
85 ms |
71416 KB |
ans=YES N=1824 |
47 |
Correct |
92 ms |
71416 KB |
ans=YES N=1981 |
48 |
Correct |
82 ms |
71288 KB |
ans=YES N=1814 |
49 |
Correct |
89 ms |
71416 KB |
ans=YES N=1854 |
50 |
Correct |
86 ms |
71416 KB |
ans=YES N=1831 |
51 |
Correct |
94 ms |
71544 KB |
ans=YES N=2000 |
52 |
Correct |
100 ms |
71544 KB |
ans=YES N=1847 |
53 |
Correct |
113 ms |
71732 KB |
ans=YES N=1819 |
54 |
Correct |
91 ms |
71416 KB |
ans=YES N=1986 |
55 |
Correct |
129 ms |
72212 KB |
ans=YES N=2000 |
56 |
Correct |
133 ms |
72056 KB |
ans=YES N=1834 |
57 |
Correct |
131 ms |
72060 KB |
ans=YES N=1860 |
58 |
Correct |
136 ms |
72184 KB |
ans=YES N=1898 |
59 |
Correct |
110 ms |
71804 KB |
ans=YES N=1832 |
60 |
Correct |
160 ms |
72440 KB |
ans=YES N=1929 |
61 |
Correct |
90 ms |
71544 KB |
ans=YES N=1919 |
62 |
Correct |
125 ms |
72056 KB |
ans=YES N=1882 |
63 |
Correct |
158 ms |
72568 KB |
ans=YES N=1922 |
64 |
Correct |
89 ms |
71544 KB |
ans=YES N=1989 |
65 |
Correct |
149 ms |
71892 KB |
ans=YES N=1978 |
66 |
Correct |
121 ms |
72184 KB |
ans=YES N=1867 |
67 |
Correct |
108 ms |
71928 KB |
ans=YES N=1942 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
73976 KB |
ans=NO N=1934 |
2 |
Correct |
60 ms |
71960 KB |
ans=NO N=1965 |
3 |
Incorrect |
84 ms |
71288 KB |
Contestant's solution is not lexicographically largest at index 1698 (1345 vs 1145) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
70776 KB |
ans=YES N=1 |
2 |
Correct |
44 ms |
70904 KB |
ans=YES N=4 |
3 |
Correct |
45 ms |
70776 KB |
ans=NO N=4 |
4 |
Correct |
44 ms |
70776 KB |
ans=YES N=5 |
5 |
Correct |
45 ms |
70776 KB |
ans=YES N=9 |
6 |
Correct |
45 ms |
70776 KB |
ans=YES N=5 |
7 |
Correct |
46 ms |
70776 KB |
ans=NO N=9 |
8 |
Correct |
45 ms |
70776 KB |
ans=NO N=10 |
9 |
Correct |
47 ms |
70784 KB |
ans=YES N=10 |
10 |
Correct |
44 ms |
70784 KB |
ans=YES N=10 |
11 |
Correct |
46 ms |
70776 KB |
ans=YES N=10 |
12 |
Correct |
45 ms |
70776 KB |
ans=YES N=9 |
13 |
Correct |
44 ms |
70784 KB |
ans=YES N=9 |
14 |
Correct |
44 ms |
70776 KB |
ans=YES N=8 |
15 |
Correct |
46 ms |
70832 KB |
ans=YES N=8 |
16 |
Correct |
44 ms |
70784 KB |
ans=NO N=2 |
17 |
Correct |
43 ms |
70780 KB |
ans=YES N=17 |
18 |
Correct |
44 ms |
70776 KB |
ans=YES N=25 |
19 |
Correct |
48 ms |
70780 KB |
ans=YES N=100 |
20 |
Correct |
45 ms |
70904 KB |
ans=YES N=185 |
21 |
Correct |
48 ms |
71168 KB |
ans=NO N=174 |
22 |
Correct |
46 ms |
70776 KB |
ans=YES N=90 |
23 |
Correct |
52 ms |
70796 KB |
ans=YES N=63 |
24 |
Correct |
45 ms |
70904 KB |
ans=YES N=87 |
25 |
Correct |
47 ms |
70776 KB |
ans=YES N=183 |
26 |
Correct |
48 ms |
70904 KB |
ans=YES N=188 |
27 |
Correct |
47 ms |
70904 KB |
ans=YES N=183 |
28 |
Correct |
45 ms |
70904 KB |
ans=YES N=189 |
29 |
Correct |
46 ms |
70912 KB |
ans=YES N=200 |
30 |
Correct |
48 ms |
70904 KB |
ans=YES N=190 |
31 |
Correct |
46 ms |
70912 KB |
ans=YES N=187 |
32 |
Correct |
45 ms |
70904 KB |
ans=YES N=187 |
33 |
Correct |
47 ms |
71040 KB |
ans=YES N=182 |
34 |
Correct |
51 ms |
70904 KB |
ans=YES N=184 |
35 |
Correct |
45 ms |
70904 KB |
ans=YES N=188 |
36 |
Correct |
47 ms |
70904 KB |
ans=YES N=181 |
37 |
Correct |
46 ms |
70908 KB |
ans=YES N=188 |
38 |
Correct |
46 ms |
70904 KB |
ans=YES N=191 |
39 |
Correct |
45 ms |
70824 KB |
ans=YES N=196 |
40 |
Correct |
46 ms |
70904 KB |
ans=YES N=196 |
41 |
Correct |
45 ms |
70892 KB |
ans=YES N=196 |
42 |
Correct |
45 ms |
70904 KB |
ans=YES N=196 |
43 |
Correct |
45 ms |
70904 KB |
ans=YES N=195 |
44 |
Correct |
77 ms |
73976 KB |
ans=NO N=1934 |
45 |
Correct |
60 ms |
71928 KB |
ans=NO N=1965 |
46 |
Correct |
85 ms |
71416 KB |
ans=YES N=1824 |
47 |
Correct |
92 ms |
71416 KB |
ans=YES N=1981 |
48 |
Correct |
82 ms |
71288 KB |
ans=YES N=1814 |
49 |
Correct |
89 ms |
71416 KB |
ans=YES N=1854 |
50 |
Correct |
86 ms |
71416 KB |
ans=YES N=1831 |
51 |
Correct |
94 ms |
71544 KB |
ans=YES N=2000 |
52 |
Correct |
100 ms |
71544 KB |
ans=YES N=1847 |
53 |
Correct |
113 ms |
71732 KB |
ans=YES N=1819 |
54 |
Correct |
91 ms |
71416 KB |
ans=YES N=1986 |
55 |
Correct |
129 ms |
72212 KB |
ans=YES N=2000 |
56 |
Correct |
133 ms |
72056 KB |
ans=YES N=1834 |
57 |
Correct |
131 ms |
72060 KB |
ans=YES N=1860 |
58 |
Correct |
136 ms |
72184 KB |
ans=YES N=1898 |
59 |
Correct |
110 ms |
71804 KB |
ans=YES N=1832 |
60 |
Correct |
160 ms |
72440 KB |
ans=YES N=1929 |
61 |
Correct |
90 ms |
71544 KB |
ans=YES N=1919 |
62 |
Correct |
125 ms |
72056 KB |
ans=YES N=1882 |
63 |
Correct |
158 ms |
72568 KB |
ans=YES N=1922 |
64 |
Correct |
89 ms |
71544 KB |
ans=YES N=1989 |
65 |
Correct |
149 ms |
71892 KB |
ans=YES N=1978 |
66 |
Correct |
121 ms |
72184 KB |
ans=YES N=1867 |
67 |
Correct |
108 ms |
71928 KB |
ans=YES N=1942 |
68 |
Correct |
581 ms |
92804 KB |
ans=NO N=66151 |
69 |
Correct |
1797 ms |
156736 KB |
ans=NO N=64333 |
70 |
Execution timed out |
3588 ms |
87288 KB |
Time limit exceeded |
71 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
565 ms |
92280 KB |
ans=NO N=66151 |
2 |
Correct |
1665 ms |
156152 KB |
ans=NO N=64333 |
3 |
Execution timed out |
3554 ms |
86580 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
73976 KB |
ans=NO N=1934 |
2 |
Correct |
60 ms |
71960 KB |
ans=NO N=1965 |
3 |
Incorrect |
84 ms |
71288 KB |
Contestant's solution is not lexicographically largest at index 1698 (1345 vs 1145) |
4 |
Halted |
0 ms |
0 KB |
- |