아이디어
조건에 따라 주사위와 지도는 주사위가 움직일 때 상태를 변경합니다.
설명
import sys
input = sys.stdin.readline
delta = ((0, 1), (0, -1), (-1, 0), (1, 0))
dice = (0)*6
turned = (
(3, 1, 0, 5, 4, 2),
(2, 1, 5, 0, 4, 3),
(4, 0, 2, 3, 5, 1),
(1, 5, 2, 3, 0, 4)
)
def solution():
N, M, x, y, K = map(int, input().split())
board = (list(map(int, input().split())) for _ in range(N))
for d in map(int, input().split()):
d -= 1
nx, ny = x+delta(d)(0), y+delta(d)(1)
if N > nx >= 0 and M > ny >= 0:
temp = dice(:)
for i in range(6):
dice(i) = temp(turned(d)(i))
x, y = nx, ny
if board(x)(y):
dice(5) = board(x)(y)
board(x)(y) = 0
else:
board(x)(y) = dice(5)
print(dice(0))
solution()