2023-04-20 거리두기 확인하기
Summary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from itertools import combinations
def solution(places):
"""
["PXPXP",
"XPXPX",
"PXPXP",
"XPXPX",
"PXPXP"]
"""
ans = []
def is_manhaten_dist_followed(A, B, room):
dist = abs(A[0] - B[0]) + abs(A[1] - B[1])
if dist < 2:
return False
elif dist == 2:
if room[A[0]][B[1]] == 'X' and room[A[1]][B[0]] == 'X':
return True
elif room[(A[0] + B[0]) // 2][(A[1] + B[1]) // 2] == 'X':
return True
else:
return False
else:
return True
for k in range(5):
room = places[k]
p_set = set()
for i in range(5):
for j in range(5):
if room[i][j] == "P":
p_set.add((i, j))
if len(p_set) < 2:
ans.append(1)
continue
is_followed = True
for comb in combinations(p_set, 2):
is_each_followed = is_manhaten_dist_followed(comb[0], comb[1], room)
if is_each_followed is False:
is_followed = False
if is_followed:
ans.append(1)
else:
ans.append(0)
return ans