# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
993427 | Phuocbua | K-th path (IZhO11_kthpath) | Cpython 3 | 14 ms | 3076 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.
#Authour: Phuocbua(1501cf,peak 1605cf)()
import math
def phu_ho_di(m,n):
return math.comb(m,n)
def phu_ho_cac_cu_moi_ngay(m,n):
return phu_ho_di(m+n-2,n-1)
def luck():
b,a = map(int,input().split())
arr=[list(input()) for x in range(b)]
k=int(input())
ptr=[0,0]
str_=""
nt = 1
while ptr[0]<b and ptr[1]<a:
str_+=arr[ptr[0]][ptr[1]]
if ptr[0]==b-1:
ptr[1]+=1
elif ptr[1]==a-1:
ptr[0]+=1
else:
if ord(arr[ptr[0]+1][ptr[1]]) > ord(arr[ptr[0]][ptr[1]+1]):
if nt + phu_ho_cac_cu_moi_ngay(b-ptr[0],a-ptr[1]-1) <= k:
nt+=phu_ho_cac_cu_moi_ngay(b-ptr[0],a-ptr[1]-1)
ptr[0]+=1
else:
ptr[1]+=1
else:
if nt + phu_ho_cac_cu_moi_ngay(b-ptr[0]-1,a-ptr[1]) <= k:
nt+=phu_ho_cac_cu_moi_ngay(b-ptr[0]-1,a-ptr[1])
ptr[1]+=1
else:
ptr[0]+=1
print(str_)
luck()
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |