๋ฌธ์
https://www.acmicpc.net/problem/14499
ํ์ด
import sys
input = sys.stdin.readline
N, M, X, Y, K = map(int,input().rstrip().split())
dx = [0,0,-1,1]
dy = [1,-1,0,0] # 1 ๋, 2 ์, 3 ๋ถ, 4 ๋จ
dice = [0,0,0,0,0,0] # down left front back right up
road = []
for i in range(N):
road.append([int(x) for x in input().rstrip().split()])
command = [int(x) for x in input().rstrip().split()]
#print(road)
def move_right():
temp = dice[1]
dice[1] = dice[0]
dice[0] = dice[4]
dice[4] = dice[5]
dice[5] = temp
def move_left():
temp = dice[4]
dice[4] = dice[0]
dice[0] = dice[1]
dice[1] = dice[5]
dice[5] = temp
def move_front():
temp = dice[3]
dice[3] = dice[0]
dice[0] = dice[2]
dice[2] = dice[5]
dice[5] = temp
def move_back():
temp = dice[5]
dice[5] = dice[2]
dice[2] = dice[0]
dice[0] = dice[3]
dice[3] = temp
x, y = X, Y
for i in command:
if 0 <= x + dx[i - 1] < N and 0 <= y + dy[i - 1] < M:
x, y = x + dx[i - 1], y + dy[i - 1]
if i == 1:
move_right()
elif i == 2:
move_left()
elif i == 3:
move_back()
elif i == 4:
move_front()
if road[x][y] == 0:
road[x][y] = dice[0]
else:
dice[0] = road[x][y]
road[x][y] = 0
print(dice[5])
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Silver2] 11051๋ฒ_์ดํญ ๊ณ์ 2 (0) | 2023.02.27 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] [์ผ์ฑ SW ์ญ๋ ํ ์คํธ ๊ธฐ์ถ ๋ฌธ์ ] 17144๋ฒ_๋ฏธ์ธ๋จผ์ง ์๋ ! (0) | 2023.02.25 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 3190๋ฒ_๋ฑ (0) | 2023.02.23 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 2110๋ฒ_๊ณต์ ๊ธฐ ์ค์น (0) | 2023.02.21 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold3] 16236๋ฒ_์๊ธฐ ์์ด (0) | 2023.02.21 |