https://www.codetree.ai/missions/2/problems/move-to-larger-adjacent-cell/description
import sys
input = sys.stdin.readline
n, x, y = map(int, input().rstrip().split(" "))
x -= 1
y -= 1
graph = []
answer = []
dy = [0, 0, -1, 1]
dx = [-1, 1, 0, 0]
for _ in range(n):
temp = list(map(int, input().rstrip().split(" ")))
graph.append(temp)
### 구현부 ###
def simul():
global x, y
for i in range(4):
nx = x + dx[i]
ny = y+ dy[i]
if 0 <= nx and nx < n and 0<= ny and ny < n:
if graph[nx][ny] > graph[x][y]:
# answer.append(graph[nx][ny])
x = nx
y = ny
return True
return False
answer.append(graph[x][y])
while simul():
answer.append(graph[x][y])
print(*answer)
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 강력한 폭발 Python (0) | 2024.09.05 |
---|---|
[Codetree] 아름다운 수 Python (1) | 2024.09.05 |
[Codetree] 빙하 Python (0) | 2024.09.02 |
[Codetree] 큰 숫자만 계속 고르기 Python (0) | 2024.08.09 |
[Codetree] 정수 명령 처리 6 Python (0) | 2024.08.09 |