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

Envío 5058

Problema 0xde - Ordenar un arreglo grande

  • Autor: cams2692
  • Fecha: 2021-10-09 00:14:37 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.004 s 24 KBi
#2
Correcto
0.005 s 46 KBi
#3
Correcto
0.004 s 24 KBi
#4
Correcto
0.003 s 31 KBi
#5
Correcto
0.005 s 15 KBi
#6
Correcto
0.004 s 26 KBi
#7
Tiempo límite excedido
1.014 s 30 KBi
#8
Tiempo límite excedido
1.057 s 16 KBi
#9
Tiempo límite excedido
1.12 s 19 KBi
#10
Tiempo límite excedido
1.045 s 16 KBi
#11
Tiempo límite excedido
1.141 s 20 KBi
#12
Tiempo límite excedido
1.091 s 23 KBi
#13
Tiempo límite excedido
1.099 s 24 KBi
#14
Tiempo límite excedido
1.048 s 30 KBi
#15
Tiempo límite excedido
1.04 s 27 KBi
#16
Correcto
0.547 s 17 KBi
#17
Correcto
0.635 s 18 KBi
#18
Tiempo límite excedido
1.084 s 27 KBi
#19
Tiempo límite excedido
1.102 s 22 KBi
#20
Tiempo límite excedido
1.09 s 17 KBi
#21
Tiempo límite excedido
1.088 s 27 KBi
#22
Tiempo límite excedido
1.041 s 31 KBi
#23
Tiempo límite excedido
1.06 s 24 KBi
#24
Tiempo límite excedido
1.122 s 22 KBi
#25
Tiempo límite excedido
1.134 s 25 KBi
#26
Tiempo límite excedido
1.09 s 28 KBi
#27
Tiempo límite excedido
1.072 s 27 KBi
Puntos totales: 30 / 100

Código

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	n, _ := reader.ReadString('\n')
	n = strings.ReplaceAll(n, "\n", "")

	numbersS, _ := reader.ReadString('\n')
	numbersS = strings.ReplaceAll(numbersS, "\n", "")
	numbers := strings.Split(numbersS, " ")

	fmt.Println(strings.Join(quickSort(numbers), " "))
}

func quickSort(array []string) []string {
	if len(array) <= 1 {
		return array
	}
	pivotS := array[0]
	pivot, _ := strconv.ParseInt(pivotS, 10, 64)
	rightArray := make([]string, 0)
	leftArray := make([]string, 0)
	for i := len(array) - 1; i > 0; i-- {
		item := array[i]
		itemNumber, _ := strconv.ParseInt(item, 10, 64)
		if pivot < itemNumber {
			rightArray = append(rightArray, item)
		} else {
			leftArray = append(leftArray, item)
		}
	}
	arrayNew := make([]string, 0)
	arrayNew = append(arrayNew, quickSort(leftArray)...)
	arrayNew = append(arrayNew, pivotS)
	arrayNew = append(arrayNew, quickSort(rightArray)...)
	return arrayNew
}