n, m, x, y, k = map(int, input().split())
g = [list(map(int, input().split())) for _ in range(n)]
ops = list(map(int, input().split()))
dice = [0, 0, 0, 0, 0, 0]
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
def roll(i, dice):
a = [0] * 6
if i == 1:
a[0] = dice[3]
a[2] = dice[0]
a[3] = dice[5]
a[5] = dice[2]
elif i == 2:
a[0] = dice[2]
a[2] = dice[5]
a[3] = dice[0]
a[5] = dice[3]
elif i == 3:
a[0] = dice[4]
a[1] = dice[0]
a[4] = dice[5]
a[5] = dice[1]
else:
a[0] = dice[1]
a[1] = dice[5]
a[4] = dice[0]
a[5] = dice[4]
return a
for i in ops:
nx, ny = x + dx[i-1], y + dy[i-1]
if nx < 0 or ny < 0 or nx >= n or ny >= m:
continue
dice = roll(i, dice)
if g[nx][ny] == 0:
g[nx][ny] = dice[5]
else:
dice[5] = g[nx][ny]
g[nx][ny] = 0
print(dice[0])
x, y = nx, ny
처음 제출한 코드 : 함수를 이용해서 만들었는데 함수 앞에 저런 식으로 a를 선언하면 선언 할때마다 초기화돼서 틀림
n, m, x, y, k = map(int, input().split())
g = [list(map(int, input().split())) for _ in range(n)]
ops = list(map(int, input().split()))
dice = [0] * 6
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
def roll(i, dice):
if i == 1:
tmp = dice[2]
dice[2] = dice[0]
dice[0] = dice[3]
dice[3] = dice[5]
dice[5] = tmp
elif i == 2:
tmp = dice[0]
dice[0] = dice[2]
dice[2] = dice[5]
dice[5] = dice[3]
dice[3] = tmp
elif i == 3:
tmp = dice[4]
dice[4] = dice[5]
dice[5] = dice[1]
dice[1] = dice[0]
dice[0] = tmp
else:
tmp = dice[1]
dice[1] = dice[5]
dice[5] = dice[4]
dice[4] = dice[0]
dice[0] = tmp
return dice
for i in ops:
nx, ny = x + dx[i-1], y + dy[i-1]
if nx < 0 or ny < 0 or nx >= n or ny >= m:
continue
dice = roll(i, dice)
if g[nx][ny] == 0:
g[nx][ny] = dice[5]
else:
dice[5] = g[nx][ny]
g[nx][ny] = 0
print(dice[0])
x, y = nx, ny
이렇게 해야 맞음..
주사위(3차원) : 일차원리스트로 구현하여 동서남북(어차피 4가지) 다 해본다