코딩테스트 파이썬/Softeer

Softeer 연습문제(3단계) - 순서대로 방문하기

세용용용용 2024. 6. 28. 11:03

Candidate | Softeer Assessment UI

 

Candidate | Softeer Assessment UI

 

softeer.ai

 

나의 코드

import sys
input = sys.stdin.readline

map_size, depth_size = list(map(int,input().split()))
#print(map_size, depth_size)

map_list = []
check_points = []

result = []
def dfs(point_list, depth):
    if depth==depth_size:
        return result.append(point_list)
    elif point_list[-1]==check_points[depth]:
        dfs(point_list, depth+1)
    else:
        for move in [(1,0),(-1,0),(0,1),(0,-1)]:
            new_x = point_list[-1][0]+move[0]
            new_y = point_list[-1][1]+move[1]
            if 0<=new_x<map_size and 0<=new_y<map_size and map_list[new_x][new_y]!=1 and [new_x,new_y] not in point_list:
                dfs(point_list + [[new_x,new_y]], depth)
    
for _ in range(map_size):
    map_list.append(list(map(int,input().split())))
for _ in range(depth_size):
    x,y = list(map(int,input().split()))
    x-=1
    y-=1
    check_points.append([x,y])

dfs([check_points[0]],0)
#print(map_list, check_points)
print(len(result))