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

Envío 5351

Problema 0xde - Ordenar un arreglo grande

  • Autor: DanielP
  • Fecha: 2021-11-16 00:27:46 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.024 s 3 KBi
#2
Correcto
0.033 s 3 KBi
#3
Correcto
0.02 s 3 KBi
#4
Correcto
0.024 s 3 KBi
#5
Correcto
0.031 s 3 KBi
#6
Correcto
0.031 s 3 KBi
#7
Correcto
1.203 s 7 KBi
#8
Correcto
1.109 s 7 KBi
#9
Tiempo límite excedido
1.512 s 5 KBi
#10
Correcto
1.135 s 9 KBi
#11
Correcto
0.994 s 15 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 36, in <module>
    mergeSort(0, n - 1)
  File "script.py", line 28, in mergeSort
    mergeSort(p,q)
  File "script.py", line 28, in mergeSort
    mergeSort(p,q)
  File "script.py", line 28, in mergeSort
    mergeSort(p,q)
  [Previous line repeated 12 more times]
  File "script.py", line 30, in mergeSort
    merge(p,q,r)
  File "script.py", line 18, in merge
    if L[i] <= R[j]:
IndexError: list index out of range
0.101 s 14 KBi
#13
Correcto
1.296 s 14 KBi
#14
Correcto
1.061 s 14 KBi
#15
Correcto
1.318 s 14 KBi
#16
Correcto
1.024 s 14 KBi
#17
Correcto
0.977 s 14 KBi
#18
Correcto
0.949 s 15 KBi
#19
Correcto
0.926 s 14 KBi
#20
Correcto
0.922 s 5 KBi
#21
Correcto
1.361 s 14 KBi
#22
Correcto
0.853 s 14 KBi
#23
Correcto
1.101 s 14 KBi
#24
Correcto
0.923 s 15 KBi
#25
Correcto
1.499 s 15 KBi
#26
Correcto
1.296 s 15 KBi
#27
Correcto
1.338 s 15 KBi
Puntos totales: 93 / 100

Código

import random

def merge(p,q,r):
   global A
   n1 = q - p + 1
   n2 = r - q
   L=[]
   R=[]
   for i in range(n1):
      L.append(A[p + i])
   for j in range(n2):
      R.append(A[q + j + 1])
   L.append(1000000000)
   R.append(1000000000)
   i=0
   j=0
   for k in range(p,r + 1):
      if L[i] <= R[j]:
         A[k] = L[i]
         i += 1
      else:
         A[k] = R[j]
         j += 1
           
def mergeSort(p,r):
   if p < r:
      q = int((p + r) / 2)
      mergeSort(p,q)
      mergeSort(q+1,r)
      merge(p,q,r)
      
n = int(input())
A = [int(x) for x in input().split()]
#print(A)
if n != 1:
    mergeSort(0, n - 1)

for i in range(len(A)):
    print(A[i], end = " ")