답안 #112399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112399 2019-05-19T14:59:23 Z keanu K번째 경로 (IZhO11_kthpath) Python 3
0 / 100
23 ms 3332 KB
n,m = input().split(' ')
n = int(n)
m = int(m)
tree = []
for i in range(n):
    inputs=input()
    tree.append([])
    for j in range(m):
        
        tree[i].append(inputs[j])        



possibles=[]
leng=m+n-1


stack = [([0,0], tree[0][0])]



while len(stack)>0:
    a = stack.pop()

    i = a[0][0]
    j = a[0][1]
    stri=a[1]

    try:
        tree[i][j+1]
        if len( stri+tree[i][j+1])==leng:
            possibles.append(stri+tree[i][j+1])
        else:    
            stack.append( ([i, j+1], stri+tree[i][j+1]))
    except IndexError:
            pass

    try:
        tree[i+1][j]
        if len( stri+tree[i+1][j])==leng:
            possibles.append(stri+tree[i+1][j])
        else:    
            stack.insert(0, ([i+1, j], stri+tree[i+1][j]))         

    except IndexError:
            pass  

     
possibles.sort()
possibles

print(possibles[int(input())-1])
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 3332 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -