This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 340
#define mp make_pair
#define mid (l+r)/2
#define le node * 2
#define ri node * 2 + 1
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
#define gc getchar_unlocked
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef pair<double,ll>pdi;
const ll inf=1e18;
const ll Mod=1e9+7;
const ld Pi=acos(-1) ;
int n , t , yes = 0 , num = 0 ;
vi ans ;
map < pi , int > Node , who , done , crnt ;
unordered_map < int , pi > id ;
int X [] = { 0 , 1 , 1 , 1 , 0 , -1 , -1 , -1 } ;
int Y [] = { 1 , 1 , 0 , -1 , -1 , -1 , 0 , 1 } ;
void ok ( int x , int y ) {
if ( done [mp(x,y)] || crnt [mp(x,y)] || yes ) return ;
num ++ ;
crnt [mp(x,y)] = 1 ;
if ( num >= (n/4)*(n/4)*4 ) {
yes = 1 ;
return ;
}
for ( int i = 0 ; i < 8 ; i ++ ) {
int nx = x + X [i] ;
int ny = y + Y [i] ;
ok ( nx , ny ) ;
}
}
int check () {
if ( ans .size () != n ) return 0 ;
done .clear () ;
for ( int i = 0 ; i < n ; i ++ ) {
yes = num = 0 ;
crnt .clear () ;
pi ret = id [i] ;
ok ( ret .fi , ret .se ) ;
if ( ! yes ) return 0 ;
done [ret] = 1 ;
}
cout << "YES" << endl ;
for ( auto u : ans ) {
cout << u + 1 << endl ;
}
exit (0) ;
}
void bfs ( int stx , int sty ) {
done .clear () ;
ans .clear () ;
done [mp(stx,sty)] = 1 ;
queue < pi > q ;
q .push ( { stx , sty } ) ;
while ( q .size () ) {
pi ret = q .front () ;
q .pop () ;
ans .pb ( who [ret] ) ;
for ( int i = 0 ; i < 8 ; i ++ ) {
int nx = ret.fi + X [i] ;
int ny = ret.se + Y [i] ;
if ( done [mp(nx,ny)] ) C ;
if ( ! Node [mp(nx,ny)] ) C ;
done [mp(nx,ny)] = 1 ;
q .push ( { nx , ny } ) ;
}
}
}
int main () {
cin >> n >> t ;
for ( int i = 0 ; i < n ; i ++ ) {
int x , y ;
cin >> x >> y ;
Node [ mp ( x , y ) ] = 1 ;
who [ mp ( x , y ) ] = i ;
id [i] = mp ( x , y ) ;
}
pi xxx = { -1 , -1 } ;
for ( int i = 0 ; i < n ; i ++ ) {
int x = id [i] .fi , y = id [i] .se , NUM = 0 ;
for ( int j = 0 ; j < 8 ; j ++ ) {
int nx = x + X [j] ;
int ny = y + Y [j] ;
NUM += Node [mp(nx,ny)] ;
}
xxx = max ( xxx , { NUM , i } ) ;
}
bfs ( id [xxx.se] .fi , id [xxx.se] .se ) ;
check () ;
cout << "NO" << endl ;
}
Compilation message (stderr)
skyscrapers.cpp: In function 'int check()':
skyscrapers.cpp:56:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
56 | if ( ans .size () != n ) return 0 ;
| ~~~~~~~~~~~~~^~~~
# | 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... |