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

Envío 3621

Problema 0xde - Ordenar un arreglo grande

  • Autor: jocarmp08
  • Fecha: 2021-04-04 03:53:31 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.039 s 6 KBi
#2
Correcto
0.026 s 3 KBi
#3
Correcto
0.034 s 3 KBi
#4
Correcto
0.032 s 4 KBi
#5
Correcto
0.028 s 7 KBi
#6
Correcto
0.018 s 3 KBi
#7
Correcto
0.101 s 5 KBi
#8
Correcto
0.161 s 9 KBi
#9
Correcto
0.15 s 8 KBi
#10
Correcto
0.322 s 11 KBi
#11
Correcto
0.139 s 14 KBi
#12
Correcto
0.139 s 17 KBi
#13
Tiempo límite excedido
1.057 s 14 KBi
#14
Tiempo límite excedido
1.058 s 14 KBi
#15
Tiempo límite excedido
1.047 s 14 KBi
#16
Correcto
0.829 s 14 KBi
#17
Correcto
0.958 s 14 KBi
#18
Tiempo límite excedido
1.071 s 15 KBi
#19
Tiempo límite excedido
1.051 s 14 KBi
#20
Correcto
0.157 s 5 KBi
#21
Tiempo límite excedido
1.076 s 14 KBi
#22
Tiempo límite excedido
1.056 s 14 KBi
#23
Tiempo límite excedido
1.042 s 14 KBi
#24
Tiempo límite excedido
1.05 s 15 KBi
#25
Tiempo límite excedido
1.019 s 15 KBi
#26
Tiempo límite excedido
1.036 s 15 KBi
#27
Tiempo límite excedido
1.043 s 15 KBi
Puntos totales: 56 / 100

Código

import random


def exchange(array, i, j):
    array[i], array[j] = array[j], array[i]


def sort(array, lo, hi):
    if hi <= lo:
        return

    less_than_idx = lo
    greater_than_idx = hi
    current_idx = lo + 1

    pivot = array[lo]
    while current_idx <= greater_than_idx:
        current = array[current_idx]
        if current < pivot:
            exchange(array, less_than_idx, current_idx)
            less_than_idx += 1
            current_idx += 1
        elif current > pivot:
            exchange(array, current_idx, greater_than_idx)
            greater_than_idx -= 1
        else:
            current_idx += 1

    sort(array, lo, less_than_idx - 1)
    sort(array, greater_than_idx + 1, hi)


n = int(input())
array = [int(x) for x in input().split()]
sort(array, 0, n - 1)
print(*array)