title: "[프로그래머스] 외벽 점검 Python 파이썬 해설 (Level 3) - 이도훈"
cleanUrl: "programmers/60062"
description: "프로그래머스 Level 3 문제 [외벽 점검]의 풀이를 정리합니다."
from math import factorial, inf
import itertools
def rotate(weak, k, n):
weak = weak[k:] + [n+x for x in weak[:k]]
mn = min(weak)
return [x-mn for x in weak]
def all_permutations(dist):
x = []
for n in range(1, len(dist) + 1):
x += list(itertools.permutations(dist, n))
return x
def solution(n, weak, dist):
# 제한조건이 그리 어렵지 않아서 완전탐색으로도 풀릴 것 같다.
mn = inf
for k in range(len(weak)):
tmp = rotate(weak, k, n)
for perm in all_permutations(dist):
i, pos = 0, tmp[0]
for n_worker, d in enumerate(perm, 1):
while i < len(tmp) and tmp[i] <= pos + d:
i += 1
if i < len(tmp):
pos = tmp[i]
if i == len(tmp):
if n_worker < mn:
mn = n_worker
break
return -1 if mn == inf else mn
프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges