244. 주사위 굴리기

아현·2021년 8월 12일
0

Algorithm

목록 보기
256/400

백준




1. Python


import sys
input = sys.stdin.readline
n, m, x, y, k = map(int, input().split())

#1, 2, 3, 4, 5, 6
dice = [0] * 6
board = [list(map(int, input().split())) for _ in range(n)]

# 1: 동, 2:서, 3:북, 4: 남
mlist = list(map(int, input().split()))

dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]

for i in range(k):
    d = mlist[i] - 1
    nx = x + dx[d]
    ny = y + dy[d]

    if 0 <= nx < n and 0 <= ny < m:
        if d == 0:
            dice[0], dice[2], dice[3], dice[5] = dice[3], dice[0], dice[5], dice[2]
        elif d== 1:
            dice[0], dice[2], dice[3], dice[5] = dice[2], dice[5], dice[0], dice[3]
        elif d == 2:
            dice[0], dice[1], dice[4], dice[5] = dice[4], dice[0], dice[5], dice[1]
        else:
            dice[0], dice[1], dice[4], dice[5] = dice[1], dice[5], dice[0], dice[4]

        if board[nx][ny] == 0:
            board[nx][ny] = dice[5]
    
        else:
            dice[5] = board[nx][ny]
            board[nx][ny] = 0

        x, y = nx, ny
        print(dice[0])
profile
Studying Computer Science

0개의 댓글