-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14499.py
More file actions
66 lines (47 loc) · 1.19 KB
/
14499.py
File metadata and controls
66 lines (47 loc) · 1.19 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
n, m, x, y, k = map(int, input().split())
map_gird = []
for _ in range(n):
map_gird.append(list(map(int, input().split())))
command = list(map(int, input().split()))
dx = [0, 0, 0, -1, 1]
dy = [0, 1, -1, 0, 0]
dice = [0] * 6
def roll_dice(direc):
if direc == 1:
temp = dice[0]
dice[0] = dice[3]
dice[3] = dice[5]
dice[5] = dice[2]
dice[2] = temp
elif direc == 2:
temp = dice[0]
dice[0] = dice[2]
dice[2] = dice[5]
dice[5] = dice[3]
dice[3] = temp
elif direc == 3:
temp = dice[0]
dice[0] = dice[4]
dice[4] = dice[5]
dice[5] = dice[1]
dice[1] = temp
elif direc == 4:
temp = dice[0]
dice[0] = dice[1]
dice[1] = dice[5]
dice[5] = dice[4]
dice[4] = temp
for i in range(k):
direc = command[i]
nx = x + dx[direc]
ny = y + dy[direc]
if 0 <= nx < n and 0 <= ny < m:
x = nx
y = ny
roll_dice(direc)
if map_gird[x][y] == 0:
map_gird[x][y] = dice[5]
else:
dice[5] = map_gird[x][y]
map_gird[x][y] = 0
print(dice[0])