Skip to content

Commit 8739445

Browse files
committed
[PGS] 고고학 최고의 발견 / Level 3 / 스킬체크 -> 실패 / 70분(실패)
1 parent 8a65248 commit 8739445

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from itertools import product
2+
3+
4+
def solution(clockHands):
5+
answer = 9876543210
6+
n = len(clockHands)
7+
8+
dy = [-1, 1, 0, 0, 0]
9+
dx = [0, 0, -1, 1, 0]
10+
11+
def rotate(a, b, t, arr):
12+
for k in range(5):
13+
y, x = a + dy[k], b + dx[k]
14+
if 0 <= y < n and 0 <= x < n:
15+
arr[y][x] = (arr[y][x] + t) % 4
16+
17+
for case in product(range(4), repeat=n): # 첫째줄 최대4번까지 회전 한다는 가정 하에 모든 경우의 수를 만든다.
18+
arr = [i[:] for i in clockHands] # 깊은 복사는 deepcopy 보다 slicing 이 빠름
19+
20+
for j in range(n): # case 를 가지고 첫번째 줄만 회전 시킨다
21+
rotate(0, j, case[j], arr)
22+
23+
result = sum(case) # 첫번째 줄 조작 횟수의 합
24+
25+
for i in range(1, n): # 두번째 줄부터 체크
26+
for j in range(n):
27+
if arr[i-1][j]: # 12시 가있지 않은 시계만 조작
28+
temp = 4 - arr[i-1][j] # 12시에 가도록 하기 위한 조작 횟수
29+
rotate(i, j, temp, arr) # 회전
30+
result += temp # 조작 횟수 누적
31+
32+
if sum(arr[n-1]): # 마지막 라인에 12시를 향하지 않는 시계가 존재
33+
continue # pass
34+
35+
answer = min(answer, result) # 시계가 모두 12시를 가리킨다면 answer을 최솟값으로 갱신
36+
37+
return answer

0 commit comments

Comments
 (0)