238. 톱니바퀴

아현·2021년 8월 6일
0

Algorithm

목록 보기
248/400
post-custom-banner

백준




Python


import sys
from collections import deque
input = sys.stdin.readline

g_list = [deque(list(map(int, input().rstrip()))) for _ in range(4)]

r = int(input())
r_list = []
for _ in range(r):
    num, direction = map(int, input().split())
    r_list.append((num - 1, direction))


def left(n, d): 
    if n < 0:
        return 
    if g_list[n][2] != g_list[n + 1][6]:
        left(n - 1, -d)
        g_list[n].rotate(d)

def right(n, d): 
    if n > 3:
        return
    if g_list[n][6] != g_list[n - 1][2]:
        right(n + 1, -d)
        g_list[n].rotate(d)

for n, d in r_list:
    left(n - 1, -d)
    right(n + 1, -d)
    g_list[n].rotate(d)

print(g_list[0][0] * 1 + g_list[1][0] * 2 + g_list[2][0] * 4 + g_list[3][0] * 8)
profile
For the sake of someone who studies computer science
post-custom-banner

0개의 댓글