실패 코드..
def solution(places):
direction_x = [1, -1, 0, 0]
direction_y = [0, 0, 1, -1]
answer = []
def dfs(x, y, place, standard):
visited[x][y] = True
for d in range(4):
next_x = direction_x[d] + x
next_y = direction_y[d] + y
if 0 <= next_x < 5 and 0 <= next_y < 5 and visited[next_x][next_y] == False:
if place[next_x][next_y] == 'X':
break
elif place[next_x][next_y] == 'P':
manhattan = abs(
next_x - standard[0]) + abs(next_y - standard[1])
if manhattan <= 2:
return 0
return 1
else:
dfs(next_x, next_y, place, standard)
for place in places:
not_able = 0
for x in range(5):
for y in range(5):
if place[x][y] == 'P':
visited = [[False] * 5] * 5
standard = [x, y]
flag = dfs(x, y, place, standard)
if flag == 0:
not_able = 1
break
if not_able == 1:
answer.append(0)
else:
answer.append(1)
return answer