# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112399 | keanu | K-th path (IZhO11_kthpath) | Cpython 3 | 23 ms | 3332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |