Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.091 s | 17 KBi |
#2 |
Correcto
|
0.091 s | 17 KBi |
#3 |
Correcto
|
0.102 s | 16 KBi |
#4 |
Correcto
|
0.111 s | 18 KBi |
#5 |
Correcto
|
0.102 s | 17 KBi |
#6 |
Correcto
|
0.104 s | 16 KBi |
#7 |
Tiempo límite excedido
|
1.165 s | 95 KBi |
#8 |
Correcto
|
0.911 s | 102 KBi |
#9 |
Correcto
|
0.769 s | 100 KBi |
#10 |
Correcto
|
0.876 s | 99 KBi |
#11 |
Tiempo límite excedido
|
1.071 s | 95 KBi |
#12 |
Correcto
|
0.802 s | 108 KBi |
#13 |
Correcto
|
0.925 s | 105 KBi |
#14 |
Correcto
|
0.753 s | 98 KBi |
#15 |
Correcto
|
0.915 s | 102 KBi |
#16 |
Tiempo límite excedido
|
1.076 s | 94 KBi |
#17 |
Correcto
|
0.94 s | 102 KBi |
#18 |
Correcto
|
0.755 s | 97 KBi |
#19 |
Correcto
|
0.798 s | 102 KBi |
#20 |
Correcto
|
0.803 s | 99 KBi |
#21 |
Correcto
|
0.794 s | 100 KBi |
#22 |
Correcto
|
0.874 s | 100 KBi |
#23 |
Correcto
|
0.808 s | 99 KBi |
#24 |
Correcto
|
0.857 s | 109 KBi |
#25 |
Correcto
|
0.867 s | 100 KBi |
#26 |
Correcto
|
0.815 s | 97 KBi |
#27 |
Correcto
|
0.854 s | 97 KBi |
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] array = new int[n]; for (int i=0; i<n; i++){ array[i] = scanner.nextInt(); } int[] orderedArray = mergeSort(array, 0, n-1); for(int i=0; i<n; i++){ System.out.print(orderedArray[i] + " "); } } private static int[] mergeSort(int[] array, int start, int end){ if(start == end){ return new int[]{array[start]}; } int middle = (end+start)/2; int startLeft = start; int endLeft = middle; int startRight = middle+1; int endRight = end; int[] orderedLeft = mergeSort(array, startLeft, endLeft); int[] orderedRight = mergeSort(array, startRight, endRight); int leftPointer = 0; int rightPointer = 0; int n = end - start + 1; int[] orderedArray = new int[n]; int orderedArrayPointer = 0; while (orderedArrayPointer < n){ int leftValue = leftPointer<orderedLeft.length ? orderedLeft[leftPointer] : Integer.MAX_VALUE; int rightValue = rightPointer<orderedRight.length ? orderedRight[rightPointer] : Integer.MAX_VALUE; if(leftValue<rightValue){ orderedArray[orderedArrayPointer] = leftValue; leftPointer++; } else { orderedArray[orderedArrayPointer] = rightValue; rightPointer++; } orderedArrayPointer++; } return orderedArray; } }