Point πŸ’‘


My Solution



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]이 항상 μœ„μͺ½λ©΄