Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions MIMO/14499.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
##문제 복기 : 주사위가 굴러갈 때마다 어떻게 되는지 알아내는게 포인트, 머릿속에서 잘 굴리다보면 규칙이 나온다.

import sys
from collections import deque
wei = deque([4,1,3])
hei = deque([2,1,5,6])
dice = [0,0,0,0,0,0]
dx = [0,0,-1,1]
dy = [1,-1,0,0]
N,M,x,y,K = map(int, sys.stdin.readline().split())
board = []
for i in range(N):
a = list(map(int,sys.stdin.readline().split()))
board.append(a)
order = list(map(int, sys.stdin.readline().split()))
up = 1
for j in order:
if x+dx[j-1] < 0 or x+dx[j-1] >=N or y+dy[j-1]<0 or y+dy[j-1]>=M:
continue
else:
x += dx[j-1]
y += dy[j-1]
if j == 1:
cnt = wei.pop()
cnt1 = hei.pop()
hei.append(cnt)
wei.appendleft(cnt1)
hei[1] = wei[1]
elif j == 2:
cnt = wei.popleft()
cnt1 = hei.pop()
wei.append(cnt1)
hei.append(cnt)
hei[1] = wei[1]
elif j == 3:
hei.append(hei.popleft())
wei[1] = hei[1]
elif j == 4:
hei.appendleft(hei.pop())
wei[1] = hei[1]
up = hei[1]
print(dice[up-1])
if board[x][y] == 0:
board[x][y] = dice[7-up-1]
else:
dice[7-up-1] = board[x][y]
board[x][y] = 0
61 changes: 61 additions & 0 deletions su-lim/14499.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import sys
input = sys.stdin.readline

# init
N, M, y, x, K = map(int, input().split())
maps = []
for _ in range(N):
maps.append(list(map(int, input().split())))
command = list(map(int, input().split()))

dxdy = [(0,0), (1,0), (-1,0), (0,-1), (0,1)]
dices = [0,0,0,0,0,0]
result = []

def roll(direct, dices):
tmp_dices = dices.copy()
if direct == 1: #동
tmp_dices[2] = dices[0]
tmp_dices[5] = dices[2]
tmp_dices[0] = dices[3]
tmp_dices[3] = dices[5]
if direct == 2: #서
tmp_dices[3] = dices[0]
tmp_dices[0] = dices[2]
tmp_dices[5] = dices[3]
tmp_dices[2] = dices[5]
if direct == 3: #북
tmp_dices[1] = dices[0]
tmp_dices[5] = dices[1]
tmp_dices[0] = dices[4]
tmp_dices[4] = dices[5]
if direct == 4: #남
tmp_dices[4] = dices[0]
tmp_dices[0] = dices[1]
tmp_dices[5] = dices[4]
tmp_dices[1] = dices[5]
return tmp_dices


# main
for com in command:

# 1. 이동할 수 있나?
dx, dy = dxdy[com]
if x+dx < 0 or y+dy < 0 or x+dx >= M or y+dy >= N:
continue
x += dx
y += dy

# 2. 이동 후 주사위 결과 / roll
dices = roll(com, dices)

# 3. 윗면 출력
print(dices[0])

# 4. 바닥면 업데이트
if maps[y][x] == 0:
maps[y][x] = dices[-1]
else:
dices[-1] = maps[y][x]
maps[y][x] = 0