알고리즘 문제 풀이/이코테

[이코테 Python] 구현 실전문제 3 게임 개발

파란색 가운 2023. 10. 3. 17:13
import sys
# sys.stdin.readline()
from collections import deque
sys.setrecursionlimit(100000000)
import heapq
INF = int(1e9)

N,M = map(int,input().split())
x,y,direction = map(int,input().split())
d =[[0] * M for _ in range(N)]
array = []
d[x][y] = 1
for i in range(N):
    array.append(list(map(int,input().split())))

dx = [-1,0,1,0]
dy = [0,1,0,-1]

def turn_left():
    global direction
    direction -=1
    if direction == -1:
        dircetion = 3

count = 1 # 처음 방문지는 이미 방문처리 했으므로
turn_time = 0
while True:
    turn_left()
    nx = x+ dx[direction]
    ny = y+ dy[direction]
    if d[nx][ny] == 0 and array[nx][ny] == 0: # 원래의 array 배열을 훼손하지 않기 위해서..
        d[nx][ny] = 1
        x = nx
        y = ny
        count +=1
        turn_time = 0 # 0인걸 발견했으니까 안에서 턴을 0으로 초기화해줘야 한다 
        continue
    else:
        turn_time = 1 # 갈 곳이 없다는 의미이므로 왼쪽으로 회전시켜준다.
    
    if turn_time == 4:
        nx = x - dx[direction]
        ny = y - dy[direction]
        if array[nx][ny] == 0:# 뒤로 이동할 수 있다
            x = nx
            y= ny
        else:
            break
        turn_time = 0

print(count)

풀릴랑 말랑 하다가 한시간동안 못 풀어서 해설지 결국 봤다

금융권 코테 보려면 구현 잘해야하는데 이걸 한시간동안 헤맸다니

열심히 하겠습니다 ㅎㅅㅎ,,