๐Ÿ—๏ธ Algorithm/๐ŸŸฉ ๋ฐฑ์ค€

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold4] [์‚ผ์„ฑ SW ์—ญ๋Ÿ‰ ํ…Œ์ŠคํŠธ ๊ธฐ์ถœ ๋ฌธ์ œ] 14499๋ฒˆ_์ฃผ์‚ฌ์œ„ ๊ตด๋ฆฌ๊ธฐ

Dbswnstjd 2023. 2. 24. 00:05

๋ฌธ์ œ

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

 

14499๋ฒˆ: ์ฃผ์‚ฌ์œ„ ๊ตด๋ฆฌ๊ธฐ

์ฒซ์งธ ์ค„์— ์ง€๋„์˜ ์„ธ๋กœ ํฌ๊ธฐ N, ๊ฐ€๋กœ ํฌ๊ธฐ M (1 ≤ N, M ≤ 20), ์ฃผ์‚ฌ์œ„๋ฅผ ๋†“์€ ๊ณณ์˜ ์ขŒํ‘œ x, y(0 ≤ x ≤ N-1, 0 ≤ y ≤ M-1), ๊ทธ๋ฆฌ๊ณ  ๋ช…๋ น์˜ ๊ฐœ์ˆ˜ K (1 ≤ K ≤ 1,000)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ์ง€

www.acmicpc.net

ํ’€์ด

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])