[백준] 주사위 굴리기

[백준] 주사위 굴리기

https://www.acmicpc.net/problem/14499



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
import copy
input = sys.stdin.readline

N, M, x, y, K, board, move = [None] * 7


def init():
global N, M, x, y, K, board, move

N, M, x, y, K = list(map(int, input().split(' ')))
board = [[-1] * M for _ in range(N)]
board[x][y] = 0
for i in range(N):
for j, value in enumerate(map(int, input().split(' '))):
board[i][j] = value
move = list(map(int, input().split(' ')))


def move_dice(dice, direct):
if direct == 1: # right
dice = [dice[2], dice[0], dice[5], dice[3], dice[4], dice[1]]
elif direct == 2: # left
dice = [dice[1], dice[5], dice[0], dice[3], dice[4], dice[2]]
elif direct == 3: # up
dice = [dice[4], dice[1], dice[2], dice[0], dice[5], dice[3]]
else: # down
dice = [dice[3], dice[1], dice[2], dice[5], dice[0], dice[4]]
return dice


def solution():
global move, x, y
# up, east, west, norse, south, down
dice = [0] * 6
dxdy = [(0, 0), (0, 1), (0, -1), (-1, 0), (1, 0)]
for m in move:
if 0 <= x + dxdy[m][0] < N and 0 <= y + dxdy[m][1] < M:
dice = move_dice(copy.deepcopy(dice), m)
x += dxdy[m][0]
y += dxdy[m][1]
if board[x][y] == 0:
board[x][y] = dice[5]
else:
dice[5] = board[x][y]
board[x][y] = 0
print(dice[0])


init()
solution()

Author

Jinki Kim

Posted on

2021-10-22

Updated on

2021-10-23

Licensed under

댓글