μμ΄λμ΄μ λ¬Έμ ν΄κ²° λ°©λ²μ κ±°μ λμΌνμΌλ, κ°μ λ°κΎΈλ κ³Όμ μμ λ€μκ³Ό κ°μ΄ κ°μ λ°κΏμ μλ‘ μΆ©λνλ κ²½μ°κ° λ°μ
dice['a'] = dice['b']
dice['b'] = dice['d']
dice['c'] = dice['f']
...
β 2κ°μ§λ‘ μͺΌκ°μ΄ κ°μ λ°κΏμ€μΌνλ€!
# λ¨Όμ κ°μ 미리 μ μ₯ν΄λκ³ ,
a, b, c, d, e, f = dice[0], dice[1], dice[2], dice[3], dice[4], dice[5]
# λͺ¨λμ λ°λΌ μ μ₯ν΄ λμ κ°μ λ£λλ€.
if mode == 1:
dice[0], dice[1], dice[2], dice[5] = f, a, b, c
μ¬κΈ°μ μ£Όμ¬μ μ κ°λλ λ€μκ³Ό κ°κ³ , dice[1]μ΄ νμ μλ©΄, dice[5]κ° νμ μλ«λ©΄μ΄λ€!
d
a, b, c
e
f
ν¨μ μμμ μ½λλ₯Ό λ€ μ μ κ²½μ°, λκ°μ μ½λλ₯Ό λ°λ³΅νμ¬ μμ±νκ² λλ€ β μνμ’μ° μ’ν λ₯Ό μ΄μ©νμ¬ μ μμμ νμΈνλ μμ
μ νμ.
import sys
# λκ°μ μ½λκ° μ ν -> λ°κΉ₯μΌλ‘ λΉΌλ΄μ μκ° -> μνμ’μ° μ’ν νμ©
def move(mode):
a, b, c, d, e, f = dice[0], dice[1], dice[2], dice[3], dice[4], dice[5]
if mode == 1:
dice[0], dice[1], dice[2], dice[5] = f, a, b, c
elif mode == 2:
dice[0], dice[1], dice[2], dice[5] = b, c, f, a
elif mode == 3:
dice[1], dice[3], dice[4], dice[5] = e, b, f, d
else:
dice[1], dice[3], dice[4], dice[5] = d, f, b, e
input = sys.stdin.readline
n, m, x, y, k = map(int, input().split())
board = [] # map λ³μ -> νμ΄μ¬ μλ¬λΈ
for _ in range(n):
board.append(list(map(int, input().split())))
orders = list(map(int, input().split()))
dice = [0, 0, 0, 0, 0, 0]
# d
# a, b, c
# e
# f
# λ : 1, μ : 2, λΆ : 3, λ¨ : 4
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
nx, ny = x, y
for i in orders:
nx += dx[i-1]
ny += dy[i-1]
if nx < 0 or nx >= n or ny < 0 or ny >= m:
nx -= dx[i-1]
ny -= dy[i-1]
continue
move(i)
if board[nx][ny] == 0:
board[nx][ny] = dice[-1] # dice[5]κ° νμ μλμͺ½λ©΄
else:
dice[-1] = board[nx][ny]
board[nx][ny] = 0
print(dice[1]) # dice[1]μ΄ νμ μμͺ½λ©΄