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

Envío 1402

Problema 0xdd - Ordenar un arreglo pequeño

  • Autor: Mejibyte
  • Fecha: 2020-10-25 04:56:05 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.019 s 3 KBi
#2
Correcto
0.026 s 3 KBi
#3
Correcto
0.029 s 3 KBi
#4
Correcto
0.021 s 3 KBi
#5
Correcto
0.028 s 3 KBi
#6
Correcto
0.026 s 3 KBi
#7
Correcto
0.027 s 3 KBi
#8
Correcto
0.019 s 3 KBi
#9
Correcto
0.028 s 3 KBi
#10
Correcto
0.027 s 3 KBi
#11
Correcto
0.081 s 7 KBi
#12
Correcto
0.046 s 7 KBi
#13
Correcto
0.077 s 7 KBi
#14
Correcto
0.045 s 8 KBi
#15
Correcto
0.039 s 7 KBi
#16
Correcto
0.037 s 7 KBi
#17
Correcto
0.064 s 7 KBi
#18
Correcto
0.044 s 7 KBi
#19
Correcto
0.057 s 7 KBi
#20
Correcto
0.066 s 7 KBi
Puntos totales: 100 / 100

Código

import sys

def sort(array):
  n = len(array)
  if n == 0:
    return []
  new_element = array[-1]
  previous_elements = sort(array[0:-1])

  # Find last element in previous_elements that is
  # Now insert last element at the right place.
  for at in range(len(previous_elements)-1, -1, -1):
      if previous_elements[at] <= new_element:
        return previous_elements[0:at+1] + [new_element] + previous_elements[at+1:]

  return [new_element] + previous_elements

if __name__ == "__main__":
  sys.setrecursionlimit(2000)
  _ = input()
  sorted = sort([int(x) for x in input().split()])
  print(" ".join([str(x) for x in sorted]))