你们都是TLE,只有我是MLE???

P1923 【深基9.例4】求第 k 小的数

SakuraTao @ 2021-01-21 22:07:37

用的是分治,但是后两个MLE了,呜呜呜,是不是python必然MLE,到现在还没有一个用Python通过的,哭了

n,k = map(int,input().strip().split())
num = input().strip().split()
num = [int(i) for i in num]
def partition(seq):
    pi = seq[0]
    lo = [x for x in seq[1:] if x<=pi]
    hi = [x for x in seq[1:] if x>pi]
    return lo,pi,hi
def select(seq,k):
    lo,pi,hi = partition(seq)

    m = len(lo)
    if m == k:
        return pi
    elif m < k:
        return select(hi,k-m-1)
    else:
        return select(lo,k)
print(select(num,k))

by EuphoricStar @ 2021-01-21 22:10:45

@SakuraTao 是的


by ADay @ 2021-01-21 22:21:49

@SakuraTao py的栈空间很小,递归很容易爆栈MLE


by Aw顿顿 @ 2021-01-21 22:25:54

Py 真的有办法避免 MLE 么


by mamingxiao @ 2021-01-21 23:17:16

这题Py没人通过


by impuk @ 2021-01-22 10:04:23

py不mle也会tle。py输入太慢。

Pascal勉强卡过(((


|