https://www.codetree.ai/missions/5/problems/add-all-the-numbers-on-the-path/description
import sys
input = sys.stdin.readline
n, t = map(int, input().split(" "))
cmd = list(input().rstrip())
graph = []
for _ in range(n):
temp = list(map(int, input().rstrip().split(" ")))
graph.append(temp)
x = n //2
y = n //2
d = 0
# N 0 -> E 1 -> S 2 -> W 3
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
cnt = graph[x][y]
for c in cmd:
if c == "L":
d = (d+3) %4
elif c == "R":
d = (d+1) %4
elif c == "F":
nx = x + dx[d]
ny = y + dy[d]
if not (0<= nx and nx < n and 0<= ny and ny < n):
continue
x = nx
y = ny
cnt += graph[x][y]
print(cnt)
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 괄호 쌍 만들어주기 3 Python (0) | 2024.08.04 |
---|---|
[Codetree] 모이자 Python (0) | 2024.08.04 |
[Codetree] 최소공배수 구하기 Python (0) | 2024.07.30 |
[Codetree] 되돌아오기 2 Python (0) | 2024.07.29 |
[Codetree] 되돌아오기 Python (0) | 2024.07.29 |