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

Envío 2442

Problema 0xde - Ordenar un arreglo grande

  • Autor: javierandresgp
  • Fecha: 2020-12-18 18:53:30 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.027 s 3 KBi
#2
Correcto
0.024 s 3 KBi
#3
Correcto
0.023 s 3 KBi
#4
Correcto
0.025 s 3 KBi
#5
Correcto
0.03 s 3 KBi
#6
Correcto
0.026 s 3 KBi
#7
Correcto
0.964 s 5 KBi
#8
Tiempo límite excedido
1.037 s 7 KBi
#9
Correcto
0.863 s 5 KBi
#10
Tiempo límite excedido
1.01 s 9 KBi
#11
Correcto
0.953 s 14 KBi
#12
Correcto
0.808 s 13 KBi
#13
Incorrecto
0.851 s 12 KBi
#14
Incorrecto
0.828 s 12 KBi
#15
Incorrecto
0.921 s 12 KBi
#16
Tiempo límite excedido
1.053 s 12 KBi
#17
Tiempo límite excedido
1.041 s 12 KBi
#18
Incorrecto
0.845 s 12 KBi
#19
Incorrecto
0.938 s 12 KBi
#20
Tiempo límite excedido
1.025 s 6 KBi
#21
Tiempo límite excedido
1.006 s 12 KBi
#22
Incorrecto
0.993 s 12 KBi
#23
Incorrecto
0.859 s 12 KBi
#24
Incorrecto
0.922 s 12 KBi
#25
Tiempo límite excedido
1.037 s 12 KBi
#26
Incorrecto
0.922 s 12 KBi
#27
Incorrecto
0.901 s 12 KBi
Puntos totales: 38 / 100

Código

def main():
    n = int(input())
    integers = input()
    a = integers.split(" ")
    merge_sort(a)
    a = " ".join(str(number) for number in a)
    print(a)


def merge_sort(a):
    middle = int(len(a) // 2)
    left = a[:middle]
    right = a[middle:]
    if middle > 0:
        merge_sort(left)
        merge_sort(right)
    ms_helper(a, left, right)


def ms_helper(a, left, right):
    iA = iLeft = iRight = 0
    while iLeft < len(left) and iRight < len(right):
        if left[iLeft] < right[iRight]:
            a[iA] = left[iLeft]
            iLeft += 1
        else:
            a[iA] = right[iRight]
            iRight += 1
        iA +=1
    while iLeft < len(left):
        a[iA] = left[iLeft]
        iLeft += 1
        iA += 1
    while iRight < len(right):
        a[iA] = right[iRight]
        iRight += 1
        iA += 1


if __name__ == "__main__":
    main()