█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 2444

Problema 0xde - Ordenar un arreglo grande

  • Autor: javierandresgp
  • Fecha: 2020-12-18 21:02:51 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.039 s 4 KBi
#2
Correcto
0.029 s 3 KBi
#3
Correcto
0.031 s 3 KBi
#4
Correcto
0.027 s 3 KBi
#5
Correcto
0.028 s 3 KBi
#6
Correcto
0.027 s 3 KBi
#7
Tiempo límite excedido
1.046 s 8 KBi
#8
Tiempo límite excedido
1.039 s 12 KBi
#9
Tiempo límite excedido
1.065 s 6 KBi
#10
Tiempo límite excedido
1.031 s 9 KBi
#11
Tiempo límite excedido
1.014 s 13 KBi
#12
Tiempo límite excedido
1.097 s 13 KBi
#13
Tiempo límite excedido
1.092 s 12 KBi
#14
Tiempo límite excedido
1.05 s 13 KBi
#15
Tiempo límite excedido
1.017 s 13 KBi
#16
Tiempo límite excedido
1.026 s 12 KBi
#17
Tiempo límite excedido
1.027 s 12 KBi
#18
Tiempo límite excedido
1.081 s 12 KBi
#19
Tiempo límite excedido
1.08 s 12 KBi
#20
Tiempo límite excedido
1.015 s 6 KBi
#21
Tiempo límite excedido
1.078 s 12 KBi
#22
Tiempo límite excedido
1.069 s 13 KBi
#23
Tiempo límite excedido
1.088 s 13 KBi
#24
Tiempo límite excedido
1.069 s 13 KBi
#25
Tiempo límite excedido
1.05 s 13 KBi
#26
Tiempo límite excedido
1.086 s 12 KBi
#27
Tiempo límite excedido
1.012 s 12 KBi
Puntos totales: 23 / 100

Código

def heap_sort(a):
    aa = []
    for i in range(len(a) // 2 -1, -1, -1):
        a = hs_helper(a, i)
    for i in range(len(a)):
        buffer = a[0]
        a[0] = a[len(a) -1]
        a[len(a) -1] = buffer
        aa.append(buffer)
        a = a[:len(a) -1]
        a = hs_helper(a, 0)
    aa = " ".join(str(number) for number in aa)
    print(aa)


def hs_helper(a, i):
    left = 2 * i + 1
    right = 2 * i + 2
    if right <= len(a) -1:
        if a[left] <= a[right]:
            min = left
        else:
            min = right
        if a[i] > a[min]:
            buffer = a[i]
            a[i] = a[min]
            a[min] = buffer
            hs_helper(a, min)
    elif left <= len(a) -1:
        if a[i] > a[left]:
            buffer = a[i]
            a[i] = a[left]
            a[left] = buffer
    return a


def main():
    n = int(input())
    integers = input()
    a = integers.split(" ")
    heap_sort(a)


if __name__ == "__main__":
    main()