https://www.codetree.ai/missions/5/problems/small-marble-movement/description
import sys
input = sys.stdin.readline
n, time = map(int, input().split(" "))
x, y, nd = input().rstrip().split(" ")
x = int(x) - 1
y = int(y) - 1
direct = {"U": 0, "R":1, "D": 2, "L":3}
# U <-> D, R <-> L
dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]
for t in range(time):
ny = y + dx[direct[nd]]
nx = x + dy[direct[nd]]
if not (0 <= nx and nx < n and 0<= ny and ny <n):
if nd == 'L': nd = "R"
elif nd == 'R': nd = "L"
elif nd == 'U': nd = "D"
elif nd == 'D': nd = "U"
else:
x = nx
y = ny
print(x+1, y+1)
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 되돌아오기 Python (0) | 2024.07.29 |
---|---|
[Codetree] 빙빙 돌며 숫자 사각형 채우기 Python (0) | 2024.07.29 |
[Codetree] 1이 3개 이상 있는 위치 Python (0) | 2024.07.29 |
[Codetree] 문자에 따른 명령 2 Python (0) | 2024.07.29 |
[Codetree] 방향에 맞춰 이동 Python (0) | 2024.07.29 |