Submission #993427

# Submission time Handle Problem Language Result Execution time Memory
993427 2024-06-05T15:31:34 Z Phuocbua K-th path (IZhO11_kthpath) Python 3
0 / 100
14 ms 3076 KB
#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
1 Correct 11 ms 2908 KB Output is correct
2 Correct 11 ms 2908 KB Output is correct
3 Correct 14 ms 3076 KB Output is correct
4 Incorrect 11 ms 2976 KB Output isn't correct
5 Halted 0 ms 0 KB -