Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created November 19, 2019 05:21
Show Gist options
  • Save inspirit941/da76b53577120f6055cff2a354e7650d to your computer and use it in GitHub Desktop.
Save inspirit941/da76b53577120f6055cff2a354e7650d to your computer and use it in GitHub Desktop.
import sys
height, width, start_y, start_x, _ = map(int, sys.stdin.readline().split())
maps = []
for _ in range(height):
maps.append(list(map(int, sys.stdin.readline().split())))
order = list(map(int, sys.stdin.readline().split()))
class Dice:
def __init__(self):
self.t = 0
self.b = 0
self.e = 0
self.w = 0
self.n = 0
self.s = 0
dice = Dice()
for i in order:
# 동쪽
if i == 1:
dy, dx = 0, 1
ny, nx = start_y + dy, start_x + dx
# 갈 수 있는 곳이면
if 0<= ny < len(maps) and 0 <= nx < len(maps[0]):
dice.e, dice.b, dice.w, dice.t = dice.t, dice.e, dice.b, dice.w
# 맵 값이 0이면 dice의 바닥값 복사
if maps[ny][nx] == 0:
maps[ny][nx] = dice.b
else:
# 맵 값이 0이 아니면 dice 바닥에 복사, 맵 값은 0으로
dice.b = maps[ny][nx]
maps[ny][nx] = 0
print(dice.t)
start_y, start_x = ny, nx
# 서쪽
elif i == 2:
dy, dx = 0, -1
ny, nx = start_y + dy, start_x + dx
if 0<= ny < len(maps) and 0 <= nx < len(maps[0]):
dice.w, dice.b, dice.e, dice.t = dice.t, dice.w, dice.b, dice.e
if maps[ny][nx] == 0:
maps[ny][nx] = dice.b
else:
# 맵 값이 0이 아니면 dice 바닥에 복사, 맵 값은 0으로
dice.b = maps[ny][nx]
maps[ny][nx] = 0
print(dice.t)
start_y, start_x = ny, nx
# 북쪽
elif i == 3:
dy, dx = -1, 0
ny, nx = start_y + dy, start_x + dx
if 0<= ny < len(maps) and 0 <= nx < len(maps[0]):
dice.n, dice.b, dice.s, dice.t = dice.t, dice.n, dice.b, dice.s
if maps[ny][nx] == 0:
maps[ny][nx] = dice.b
else:
# 맵 값이 0이 아니면 dice 바닥에 복사, 맵 값은 0으로
dice.b = maps[ny][nx]
maps[ny][nx] = 0
print(dice.t)
start_y, start_x = ny, nx
# 남쪽
elif i == 4:
dy, dx = 1, 0
ny, nx = start_y + dy, start_x + dx
if 0<= ny < len(maps) and 0 <= nx < len(maps[0]):
dice.s, dice.t, dice.n, dice.b = dice.t, dice.n, dice.b, dice.s
if maps[ny][nx] == 0:
maps[ny][nx] = dice.b
else:
# 맵 값이 0이 아니면 dice 바닥에 복사, 맵 값은 0으로
dice.b = maps[ny][nx]
maps[ny][nx] = 0
print(dice.t)
start_y, start_x = ny, nx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment