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

Envío 3620

Problema 0xde - Ordenar un arreglo grande

  • Autor: jocarmp08
  • Fecha: 2021-04-04 03:52:38 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.027 s 3 KBi
#2
Correcto
0.03 s 3 KBi
#3
Correcto
0.022 s 4 KBi
#4
Correcto
0.025 s 4 KBi
#5
Correcto
0.037 s 4 KBi
#6
Correcto
0.036 s 4 KBi
#7
Correcto
0.136 s 5 KBi
#8
Correcto
0.21 s 7 KBi
#9
Correcto
0.195 s 6 KBi
#10
Correcto
0.351 s 13 KBi
#11
Correcto
0.218 s 14 KBi
#12
Correcto
0.175 s 14 KBi
#13
Tiempo límite excedido
1.05 s 15 KBi
#14
Tiempo límite excedido
1.049 s 15 KBi
#15
Tiempo límite excedido
1.043 s 14 KBi
#16
Tiempo límite excedido
1.056 s 14 KBi
#17
Tiempo límite excedido
1.018 s 14 KBi
#18
Correcto
0.933 s 14 KBi
#19
Tiempo límite excedido
1.037 s 14 KBi
#20
Correcto
0.215 s 5 KBi
#21
Correcto
0.923 s 15 KBi
#22
Tiempo límite excedido
1.039 s 14 KBi
#23
Tiempo límite excedido
1.004 s 14 KBi
#24
Tiempo límite excedido
1.046 s 15 KBi
#25
Tiempo límite excedido
1.06 s 15 KBi
#26
Tiempo límite excedido
1.047 s 15 KBi
#27
Correcto
0.891 s 15 KBi
Puntos totales: 60 / 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()]
random.shuffle(array)  # To avoid worst case scenario
sort(array, 0, n - 1)
print(*array)