Submission #112399

#TimeUsernameProblemLanguageResultExecution timeMemory
112399keanuK-th path (IZhO11_kthpath)Cpython 3
0 / 100
23 ms3332 KiB
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])
#Verdict Execution timeMemoryGrader output
Fetching results...