-
Notifications
You must be signed in to change notification settings - Fork 0
/
외벽점검.py
27 lines (24 loc) · 814 Bytes
/
외벽점검.py
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
from collections import deque
def solution(n, weak, dist):
dist.sort(reverse=True)
q = deque([weak])
visited = set()
visited.add(tuple(weak))
for i in range(len(dist)):
d = dist[i]
for _ in range(len(q)):
current = q.popleft()
for p in current:
l = p
r = (p + d) % n
if l < r:
temp = tuple(filter(lambda x: x < l or x > r, current))
else:
temp = tuple(filter(lambda x: x < l and x > r, current))
if len(temp) == 0:
return (i + 1)
elif temp not in visited:
visited.add(temp)
q.append(list(temp))
return -1
print(solution(12,[1, 5, 6, 10],[1, 2, 3, 4]))