Skip to content

Commit

Permalink
#14891
Browse files Browse the repository at this point in the history
  • Loading branch information
bong-u committed Dec 21, 2022
1 parent 010e8a0 commit a233610
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 손봉우/14891.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from collections import deque

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

def rotate(wheel, direction):
if direction == 1:
wheel.appendleft(wheel.pop())
else:
wheel.append(wheel.popleft())
return wheel

K = int(input())
vd = [1, -1]
res = 0

for _ in range(K):
N, D = map(int, input().split())
q = deque()
q.append((N-1, D))
visited = [False] * 4
tmp = []

while q:
cur, curD = q.popleft()
tmp.append((cur, curD))
visited[cur] = True

for v in vd:
nxt = cur+v
if 0 <= nxt < 4 and not visited[nxt]:
if (v == -1 and wheels[cur][6] != wheels[nxt][2]
or v == 1 and wheels[nxt][6] != wheels[cur][2]):
q.append((nxt, -1 if curD == 1 else 1))
visited[nxt] = True
for cur, curD in tmp:
rotate(wheels[cur], curD)

for i in range(4):
res += wheels[i][0]*(pow(2, i))
print (res)

0 comments on commit a233610

Please sign in to comment.