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

Envío 5764

Problema 0xde - Ordenar un arreglo grande

  • Autor: Franchesco
  • Fecha: 2022-02-25 14:53:23 UTC (Hace alrededor de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.02 s 3 KBi
#2
Correcto
0.016 s 3 KBi
#3
Correcto
0.024 s 3 KBi
#4
Correcto
0.019 s 3 KBi
#5
Correcto
0.024 s 3 KBi
#6
Correcto
0.014 s 3 KBi
#7
Correcto
0.081 s 5 KBi
#8
Correcto
0.802 s 8 KBi
#9
Correcto
0.613 s 5 KBi
#10
Correcto
1.037 s 9 KBi
#11
Correcto
0.221 s 14 KBi
#12
Correcto
0.077 s 14 KBi
#13
Tiempo límite excedido
1.581 s 14 KBi
#14
Tiempo límite excedido
1.52 s 14 KBi
#15
Correcto
1.18 s 14 KBi
#16
Tiempo límite excedido
1.597 s 14 KBi
#17
Tiempo límite excedido
1.555 s 14 KBi
#18
Tiempo límite excedido
1.51 s 15 KBi
#19
Correcto
1.366 s 14 KBi
#20
Correcto
1.014 s 6 KBi
#21
Correcto
1.438 s 14 KBi
#22
Tiempo límite excedido
1.558 s 14 KBi
#23
Correcto
1.427 s 14 KBi
#24
Correcto
0.393 s 15 KBi
#25
Correcto
1.179 s 15 KBi
#26
Tiempo límite excedido
1.534 s 16 KBi
#27
Tiempo límite excedido
1.533 s 14 KBi
Puntos totales: 71 / 100

Código

# Python program for implementation of heap Sort

# To heapify subtree rooted at index i.
# n is size of heap


def heapify(arr, n, i):
    largest = i  # Initialize largest as root
    l = 2 * i + 1	 # left = 2*i + 1
    r = 2 * i + 2	 # right = 2*i + 2

    # See if left child of root exists and is
    # greater than root
    if l < n and arr[largest] < arr[l]:
        largest = l

    # See if right child of root exists and is
    # greater than root
    if r < n and arr[largest] < arr[r]:
        largest = r

    # Change root, if needed
    if largest != i:
        arr[i], arr[largest] = arr[largest], arr[i]  # swap

        # Heapify the root.
        heapify(arr, n, largest)

# The main function to sort an array of given size


def heapSort(arr):
    n = len(arr)

    # Build a maxheap.
    for i in range(n//2 - 1, -1, -1):
        heapify(arr, n, i)

    # One by one extract elements
    for i in range(n-1, 0, -1):
        arr[i], arr[0] = arr[0], arr[i]  # swap
        heapify(arr, i, 0)

length = int(input())

my_array = list(map(int, input().split()))
# Driver code
arr = my_array
heapSort(arr)
n = length
print(*arr)
# This code is contributed by Mohit Kumra