주사위 굴리기
코드
import sys
dice = [[0 for _ in range(3)] for _ in range(4)]
n, m, x, y, k = map(int, sys.stdin.readline().split())
ma = []
for i in range(n):
ma.append(list(map(int, sys.stdin.readline().split())))
dir = {1 : [0, 1], 2 : [0, -1], 3 : [-1, 0], 4 : [1, 0]}
command = list(map(int, sys.stdin.readline().split()))
for i in command:
nx = x + dir[i][0]
ny = y + dir[i][1]
if 0 <= nx < n and 0 <= ny < m:
if i == 1:
tmp = dice[1][0]
dice[1][0] = dice[3][1]
tmp2 = dice[1][1]
dice[1][1] = tmp
tmp = dice[1][2]
dice[1][2] = tmp2
tmp2 = dice[3][1]
dice[3][1] = tmp
elif i == 2:
tmp = dice[1][2]
dice[1][2] = dice[3][1]
tmp2 = dice[1][1]
dice[1][1] = tmp
tmp = dice[1][0]
dice[1][0] = tmp2
tmp2 = dice[3][1]
dice[3][1] = tmp
elif i == 3:
tmp = dice[2][1]
dice[2][1] = dice[3][1]
tmp2 = dice[1][1]
dice[1][1] = tmp
tmp = dice[0][1]
dice[0][1] = tmp2
tmp2 = dice[3][1]
dice[3][1] = tmp
else:
tmp = dice[1][1]
dice[1][1] = dice[0][1]
tmp2 = dice[2][1]
dice[2][1] = tmp
tmp = dice[3][1]
dice[3][1] = tmp2
tmp2 = dice[0][1]
dice[0][1] = tmp
x, y = nx, ny
if ma[x][y] == 0:
ma[x][y] = dice[3][1]
else:
dice[3][1] = ma[x][y]
ma[x][y] = 0
print(dice[1][1])