#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
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 ;
| ~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
256 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
384 KB |
ans=NO N=4 |
4 |
Correct |
0 ms |
256 KB |
ans=YES N=5 |
5 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
6 |
Correct |
1 ms |
256 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
256 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
256 KB |
ans=NO N=10 |
9 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
10 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
11 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
12 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
13 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
14 |
Correct |
1 ms |
384 KB |
ans=YES N=8 |
15 |
Correct |
1 ms |
384 KB |
ans=YES N=8 |
16 |
Correct |
0 ms |
384 KB |
ans=NO N=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
256 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
384 KB |
ans=NO N=4 |
4 |
Correct |
0 ms |
256 KB |
ans=YES N=5 |
5 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
6 |
Correct |
1 ms |
256 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
256 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
256 KB |
ans=NO N=10 |
9 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
10 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
11 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
12 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
13 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
14 |
Correct |
1 ms |
384 KB |
ans=YES N=8 |
15 |
Correct |
1 ms |
384 KB |
ans=YES N=8 |
16 |
Correct |
0 ms |
384 KB |
ans=NO N=2 |
17 |
Correct |
2 ms |
384 KB |
ans=YES N=17 |
18 |
Correct |
5 ms |
384 KB |
ans=YES N=25 |
19 |
Incorrect |
308 ms |
3192 KB |
Contestant did not find solution |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
256 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
384 KB |
ans=NO N=4 |
4 |
Correct |
0 ms |
256 KB |
ans=YES N=5 |
5 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
6 |
Correct |
1 ms |
256 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
256 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
256 KB |
ans=NO N=10 |
9 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
10 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
11 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
12 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
13 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
14 |
Correct |
1 ms |
384 KB |
ans=YES N=8 |
15 |
Correct |
1 ms |
384 KB |
ans=YES N=8 |
16 |
Correct |
0 ms |
384 KB |
ans=NO N=2 |
17 |
Correct |
2 ms |
384 KB |
ans=YES N=17 |
18 |
Correct |
5 ms |
384 KB |
ans=YES N=25 |
19 |
Incorrect |
308 ms |
3192 KB |
Contestant did not find solution |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1664 KB |
ans=NO N=1934 |
2 |
Correct |
6 ms |
896 KB |
ans=NO N=1965 |
3 |
Execution timed out |
3622 ms |
341752 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
ans=YES N=1 |
2 |
Correct |
0 ms |
256 KB |
ans=YES N=4 |
3 |
Correct |
0 ms |
384 KB |
ans=NO N=4 |
4 |
Correct |
0 ms |
256 KB |
ans=YES N=5 |
5 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
6 |
Correct |
1 ms |
256 KB |
ans=YES N=5 |
7 |
Correct |
1 ms |
256 KB |
ans=NO N=9 |
8 |
Correct |
0 ms |
256 KB |
ans=NO N=10 |
9 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
10 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
11 |
Correct |
1 ms |
384 KB |
ans=YES N=10 |
12 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
13 |
Correct |
1 ms |
384 KB |
ans=YES N=9 |
14 |
Correct |
1 ms |
384 KB |
ans=YES N=8 |
15 |
Correct |
1 ms |
384 KB |
ans=YES N=8 |
16 |
Correct |
0 ms |
384 KB |
ans=NO N=2 |
17 |
Correct |
2 ms |
384 KB |
ans=YES N=17 |
18 |
Correct |
5 ms |
384 KB |
ans=YES N=25 |
19 |
Incorrect |
308 ms |
3192 KB |
Contestant did not find solution |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
459 ms |
21612 KB |
ans=NO N=66151 |
2 |
Correct |
407 ms |
36252 KB |
ans=NO N=64333 |
3 |
Execution timed out |
3638 ms |
662492 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1664 KB |
ans=NO N=1934 |
2 |
Correct |
6 ms |
896 KB |
ans=NO N=1965 |
3 |
Execution timed out |
3622 ms |
341752 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |