11import sys
22from collections import deque
3+
34input = sys .stdin .readline
45
5- odd = [(- 1 , 1 ), (0 , 1 ), (1 , 1 ), (1 , 0 ), (0 , - 1 ), (- 1 , 0 )] # 행, 렬 기준으로함 정각부터 정시계방향으로 순환
6+ odd = [(- 1 , 1 ), (0 , 1 ), (1 , 1 ), (1 , 0 ), (0 , - 1 ), (- 1 , 0 )] # 행, 렬 기준으로함 정각부터 정시계방향으로 순환
67even = [(- 1 , 0 ), (0 , 1 ), (1 , 0 ), (1 , - 1 ), (0 , - 1 ), (- 1 , - 1 )]
78
9+
810def bfs (x , y ):
911 q = deque ([(x , y )])
1012 count = 0
1113 while q :
1214 x , y = q .popleft ()
1315 visited [x ][y ] = 1
14- dir = even if x % 2 == 0 else odd
16+ dir = even if x % 2 == 0 else odd
1517 for i in range (6 ):
1618 dx , dy = dir [i ][0 ], dir [i ][1 ]
1719 nx , ny = x + dx , y + dy
1820
19- if 0 <= nx < h + 2 and 0 <= ny < w + 2 :
21+ if 0 <= nx < h + 2 and 0 <= ny < w + 2 :
2022 if arr [nx ][ny ] == 1 :
2123 count += 1
2224 elif arr [nx ][ny ] == 0 and not visited [nx ][ny ]:
@@ -25,13 +27,12 @@ def bfs(x, y):
2527 return count
2628
2729
28-
29- w , h = map (int , input ().split ()) # 열, 행 순서로 입력
30- arr = [[0 ] * (w + 2 )]
31- visited = [[0 ] * (w + 2 ) for _ in range (h + 2 )]
30+ w , h = map (int , input ().split ()) # 열, 행 순서로 입력
31+ arr = [[0 ] * (w + 2 )]
32+ visited = [[0 ] * (w + 2 ) for _ in range (h + 2 )]
3233for i in range (h ):
33- arr .append ([0 ]+ list (map (int , input ().split ())) + [0 ])
34- arr .append ([0 for _ in range (w + 2 )])
34+ arr .append ([0 ] + list (map (int , input ().split ())) + [0 ])
35+ arr .append ([0 for _ in range (w + 2 )])
3536
3637# for i in range(h+2):
3738# print(arr[i])
0 commit comments