Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 997071e

Browse files
committed
거리두기 확인하기
1 parent eec796d commit 997071e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

‎JongHo/Programmers/81302.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from collections import deque
2+
3+
dx = [0, 0, 1, -1]
4+
dy = [1, -1, 0, 0]
5+
6+
def solution(places):
7+
answer = []
8+
9+
def bfs(a, b, visit):
10+
q = deque()
11+
q.append((a, b, 0))
12+
visit[a][b] = 1
13+
while q:
14+
x, y, cnt = q.popleft()
15+
16+
for i in range(4):
17+
nx = x + dx[i]
18+
ny = y + dy[i]
19+
20+
if nx < 0 or nx >= 5 or ny < 0 or ny >= 5:
21+
continue
22+
if visit[nx][ny]:
23+
continue
24+
25+
if place[nx][ny] == "O" and cnt < 2:
26+
visit[nx][ny] = 1
27+
q.append((nx, ny, cnt + 1))
28+
29+
if place[nx][ny] == "P" and cnt < 2:
30+
return 0
31+
return 1
32+
33+
for place in places:
34+
flag = 1
35+
for i in range(5):
36+
for j in range(5):
37+
if place[i][j] == "P":
38+
visit = [[0, 0, 0, 0, 0] for _ in range(5)]
39+
flag = bfs(i, j, visit)
40+
if flag:
41+
break
42+
answer.append(flag)
43+
44+
return answer

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /