(SW)Array2 - Ladder2

광어회깍뚝썰기·2021년 8월 10일
0

swea-intermediate

목록 보기
36/51
for tc in range(1,10+1):
    t = int(input())
    arr=[list(map(int,input().split())) for _ in range(100)]
    min_v=10000 #가장 짧은 거리 저장용
    min_idx =0 #가장 짧은 거리의 출발선 저장용
    
    start_list = [i for i in range(99, -1, -1) if arr[0][i]]
    #사다리가 만들어질 수 있는 모든 위치(0행렬에서 유효값(1의 값)을 가지는 곳)저장
    
    for start in start_list:
        x,y=0,start
        cnt=0 #이동칸수 저장
        move=0 #방향. 위, 왼, 오를 판별하는 역할
        
        while x<99:
            if (move==0 or move==1) and y>0 and arr[x][y-1]:
                y-=1
                move=1     
            elif (move==0 or move==2) and y<99 and arr[x][y+1]: 
                y+=1
                move=2
            else:
                x+=1
                move=0
            cnt+=1
        
        if min_v>cnt:
            min_v=cnt
            min_idx=start
    
    print(f'#{t} {min_idx}')

0개의 댓글

관련 채용 정보