Created
November 19, 2019 05:21
-
-
Save inspirit941/da76b53577120f6055cff2a354e7650d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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