티스토리 뷰
https://www.acmicpc.net/problem/14891
import sys, collections
s = []
for _ in range(4):
s.append(collections.deque(list(input())))
K = int(sys.stdin.readline())
R = [list(map(int, sys.stdin.readline().split())) for _ in range(K)]
#왼쪽 톱니바퀴 확인
def left(num, direction):
if num < 0:
return
if s[num][2] != s[num+1][6]:
left(num-1, -direction)
s[num].rotate(direction)
#오른쪽 톱니바퀴 확인
def right(num, direction):
if num > 3:
return
if s[num][6] != s[num-1][2]:
right(num+1, -direction)
s[num].rotate(direction)
for i in range(K):
num = R[i][0] - 1
direction = R[i][1]
left(num-1, -direction)
right(num+1, -direction)
s[num].rotate(direction)
res = 0
if s[0][0] == '1':
res += 1
if s[1][0] == '1':
res += 2
if s[2][0] == '1':
res += 4
if s[3][0] == '1':
res += 8
print(res)
'Algorithm > Baekjoon' 카테고리의 다른 글
[백준] 1475 : 방 번호 - Python (0) | 2020.07.06 |
---|---|
[백준] 3190 : 뱀 - Python (0) | 2020.07.03 |
[백준] 14500 : 테트로미노 - Python (0) | 2020.06.30 |
[백준] 9251 : LCS - Python (0) | 2020.06.27 |
[백준] 15686 : 치킨 배달 - Python (1) | 2020.06.24 |