//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 200005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,fa[li],vis[li],c[li],bos[li];
int cev;
PIII p[li];
string s;
map<PII,int> mpp;
vector<int> vv;
vector<PII> v[li];
inline int dsu(int x){
if(x==fa[x])return x;
return fa[x]=dsu(fa[x]);
}
inline void dfs(int node){
set<PIII> st;
st.insert({4,{-c[node],node}});
while(st.size()){
auto it=st.begin();
PIII pa=*it;
int node=pa.se.se;
st.erase(it);
if(vis[node])continue;
vv.pb(node);
vis[node]=1;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i].se;
if(st.find({bos[go],{-go,go}})!=st.end())st.erase({bos[go],{-go,go}});
bos[go]--;
st.insert({bos[go],{v[node][i]}});
}
}
}
int main(void){
scanf("%d %d",&n,&t);
FOR bos[i]=4;
FOR fa[i]=i;
FOR{
int x,y;
scanf("%d %d",&a[i],&b[i]);
x=a[i];
y=b[i];
cev=0;
p[i].fi=x;
p[i].se.fi=y;
p[i].se.se=i;
if(mpp[{x-1,y}]){
cev++;
}
if(mpp[{x+1,y}]){
cev++;
}
if(mpp[{x,y-1}]){
cev++;
}
if(mpp[{x,y+1}]){
cev++;
}
c[i]=cev;
mpp[{x,y}]=i;
}
mpp.clear();
FOR{
int x,y;
x=a[i];
y=b[i];
if(mpp[{x-1,y}]){
v[mpp[{x-1,y}]].pb({c[i],i});
v[i].pb({c[mpp[{x-1,y}]],mpp[{x-1,y}]});
}
if(mpp[{x+1,y}]){
v[mpp[{x+1,y}]].pb({c[i],i});
v[i].pb({c[mpp[{x+1,y}]],mpp[{x+1,y}]});
}
if(mpp[{x,y-1}]){
v[mpp[{x,y-1}]].pb({c[i],i});
v[i].pb({c[mpp[{x,y-1}]],mpp[{x,y-1}]});
}
if(mpp[{x,y+1}]){
v[mpp[{x,y+1}]].pb({c[i],i});
v[i].pb({c[mpp[{x,y+1}]],mpp[{x,y+1}]});
}
if(mpp[{x+1,y+1}]){
v[mpp[{x+1,y+1}]].pb({c[i],i});
v[i].pb({c[mpp[{x+1,y+1}]],mpp[{x+1,y+1}]});
}
if(mpp[{x-1,y+1}]){
v[mpp[{x-1,y+1}]].pb({c[i],i});
v[i].pb({c[mpp[{x-1,y+1}]],mpp[{x-1,y+1}]});
}
if(mpp[{x-1,y-1}]){
v[mpp[{x-1,y-1}]].pb({c[i],i});
v[i].pb({c[mpp[{x-1,y-1}]],mpp[{x-1,y-1}]});
}
if(mpp[{x+1,y-1}]){
v[mpp[{x+1,y-1}]].pb({c[i],i});
v[i].pb({c[mpp[{x+1,y-1}]],mpp[{x+1,y-1}]});
}
mpp[{x,y}]=i;
}
int mx=-1;
int ind=0;
FOR{
if((int)v[i].size()>mx){ind=i;mx=v[i].size();}
}
dfs(ind);
FOR{
if(vis[i]==0){printf("NO\n");return 0;}
}
printf("YES\n");
for(int i=0;i<n;i++)printf("%d\n",vv[i]);
return 0;
}
Compilation message
skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
64 | scanf("%d %d",&n,&t);
| ~~~~~^~~~~~~~~~~~~~~
skyscrapers.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
69 | scanf("%d %d",&a[i],&b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
ans=YES N=1 |
2 |
Correct |
3 ms |
4992 KB |
ans=YES N=4 |
3 |
Correct |
4 ms |
4992 KB |
ans=NO N=4 |
4 |
Correct |
3 ms |
4992 KB |
ans=YES N=5 |
5 |
Correct |
4 ms |
4992 KB |
ans=YES N=9 |
6 |
Correct |
3 ms |
4992 KB |
ans=YES N=5 |
7 |
Correct |
4 ms |
4992 KB |
ans=NO N=9 |
8 |
Correct |
4 ms |
4992 KB |
ans=NO N=10 |
9 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
10 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
11 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
12 |
Correct |
4 ms |
5120 KB |
ans=YES N=9 |
13 |
Correct |
4 ms |
4992 KB |
ans=YES N=9 |
14 |
Correct |
4 ms |
5120 KB |
ans=YES N=8 |
15 |
Correct |
4 ms |
5120 KB |
ans=YES N=8 |
16 |
Correct |
4 ms |
4992 KB |
ans=NO N=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
ans=YES N=1 |
2 |
Correct |
3 ms |
4992 KB |
ans=YES N=4 |
3 |
Correct |
4 ms |
4992 KB |
ans=NO N=4 |
4 |
Correct |
3 ms |
4992 KB |
ans=YES N=5 |
5 |
Correct |
4 ms |
4992 KB |
ans=YES N=9 |
6 |
Correct |
3 ms |
4992 KB |
ans=YES N=5 |
7 |
Correct |
4 ms |
4992 KB |
ans=NO N=9 |
8 |
Correct |
4 ms |
4992 KB |
ans=NO N=10 |
9 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
10 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
11 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
12 |
Correct |
4 ms |
5120 KB |
ans=YES N=9 |
13 |
Correct |
4 ms |
4992 KB |
ans=YES N=9 |
14 |
Correct |
4 ms |
5120 KB |
ans=YES N=8 |
15 |
Correct |
4 ms |
5120 KB |
ans=YES N=8 |
16 |
Correct |
4 ms |
4992 KB |
ans=NO N=2 |
17 |
Correct |
4 ms |
5120 KB |
ans=YES N=17 |
18 |
Correct |
4 ms |
5120 KB |
ans=YES N=25 |
19 |
Correct |
4 ms |
5120 KB |
ans=YES N=100 |
20 |
Incorrect |
5 ms |
5120 KB |
Added cell 137 (-1,3) not reachable from infinity |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
ans=YES N=1 |
2 |
Correct |
3 ms |
4992 KB |
ans=YES N=4 |
3 |
Correct |
4 ms |
4992 KB |
ans=NO N=4 |
4 |
Correct |
3 ms |
4992 KB |
ans=YES N=5 |
5 |
Correct |
4 ms |
4992 KB |
ans=YES N=9 |
6 |
Correct |
3 ms |
4992 KB |
ans=YES N=5 |
7 |
Correct |
4 ms |
4992 KB |
ans=NO N=9 |
8 |
Correct |
4 ms |
4992 KB |
ans=NO N=10 |
9 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
10 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
11 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
12 |
Correct |
4 ms |
5120 KB |
ans=YES N=9 |
13 |
Correct |
4 ms |
4992 KB |
ans=YES N=9 |
14 |
Correct |
4 ms |
5120 KB |
ans=YES N=8 |
15 |
Correct |
4 ms |
5120 KB |
ans=YES N=8 |
16 |
Correct |
4 ms |
4992 KB |
ans=NO N=2 |
17 |
Correct |
4 ms |
5120 KB |
ans=YES N=17 |
18 |
Correct |
4 ms |
5120 KB |
ans=YES N=25 |
19 |
Correct |
4 ms |
5120 KB |
ans=YES N=100 |
20 |
Incorrect |
5 ms |
5120 KB |
Added cell 137 (-1,3) not reachable from infinity |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
6176 KB |
ans=NO N=1934 |
2 |
Correct |
11 ms |
5632 KB |
ans=NO N=1965 |
3 |
Incorrect |
15 ms |
5888 KB |
Contestant's solution is not lexicographically largest at index 1824 (1813 vs 640) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
ans=YES N=1 |
2 |
Correct |
3 ms |
4992 KB |
ans=YES N=4 |
3 |
Correct |
4 ms |
4992 KB |
ans=NO N=4 |
4 |
Correct |
3 ms |
4992 KB |
ans=YES N=5 |
5 |
Correct |
4 ms |
4992 KB |
ans=YES N=9 |
6 |
Correct |
3 ms |
4992 KB |
ans=YES N=5 |
7 |
Correct |
4 ms |
4992 KB |
ans=NO N=9 |
8 |
Correct |
4 ms |
4992 KB |
ans=NO N=10 |
9 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
10 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
11 |
Correct |
4 ms |
4992 KB |
ans=YES N=10 |
12 |
Correct |
4 ms |
5120 KB |
ans=YES N=9 |
13 |
Correct |
4 ms |
4992 KB |
ans=YES N=9 |
14 |
Correct |
4 ms |
5120 KB |
ans=YES N=8 |
15 |
Correct |
4 ms |
5120 KB |
ans=YES N=8 |
16 |
Correct |
4 ms |
4992 KB |
ans=NO N=2 |
17 |
Correct |
4 ms |
5120 KB |
ans=YES N=17 |
18 |
Correct |
4 ms |
5120 KB |
ans=YES N=25 |
19 |
Correct |
4 ms |
5120 KB |
ans=YES N=100 |
20 |
Incorrect |
5 ms |
5120 KB |
Added cell 137 (-1,3) not reachable from infinity |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
650 ms |
26724 KB |
ans=NO N=66151 |
2 |
Correct |
528 ms |
36956 KB |
ans=NO N=64333 |
3 |
Incorrect |
869 ms |
35436 KB |
Contestant's solution is not lexicographically largest at index 69316 (69235 vs 63093) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
6176 KB |
ans=NO N=1934 |
2 |
Correct |
11 ms |
5632 KB |
ans=NO N=1965 |
3 |
Incorrect |
15 ms |
5888 KB |
Contestant's solution is not lexicographically largest at index 1824 (1813 vs 640) |
4 |
Halted |
0 ms |
0 KB |
- |