Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.139 s | 13 KBi |
#2 |
Correcto
|
0.143 s | 17 KBi |
#3 |
Correcto
|
0.128 s | 13 KBi |
#4 |
Correcto
|
0.119 s | 12 KBi |
#5 |
Correcto
|
0.124 s | 16 KBi |
#6 |
Correcto
|
0.107 s | 15 KBi |
#7 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.619 s | 125 KBi |
#8 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.58 s | 125 KBi |
#9 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.547 s | 125 KBi |
#10 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.564 s | 125 KBi |
#11 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.7 s | 125 KBi |
#12 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.68 s | 125 KBi |
#13 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.644 s | 125 KBi |
#14 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.603 s | 125 KBi |
#15 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.693 s | 125 KBi |
#16 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.736 s | 125 KBi |
#17 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.654 s | 125 KBi |
#18 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.74 s | 125 KBi |
#19 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.655 s | 125 KBi |
#20 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.528 s | 125 KBi |
#21 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.635 s | 125 KBi |
#22 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.664 s | 125 KBi |
#23 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.613 s | 125 KBi |
#24 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.64 s | 125 KBi |
#25 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.66 s | 125 KBi |
#26 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.703 s | 125 KBi |
#27 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.735 s | 125 KBi |
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class Main { static int[] array; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int N = Integer.parseInt(br.readLine()); int[] nums = new int[N]; String[] numsS = br.readLine().split(" "); for (int i = 0; i < N; i++) { nums[i] = Integer.parseInt(numsS[i]); } // mergeSort(nums); array = nums; mergeSort(); String array = ""; for (int i = 0; i < N; i++) { array += " " + nums[i]; } bw.write(array.trim() + "\n"); bw.close(); br.close(); } public static void mergeSort() { // mergeSort(array, 0, array.length - 1); mergeSortI(array, array.length); } public static void mergeSort(int[] array, int startIndex, int endIndex) { if (startIndex < endIndex) { int middleIndex = (startIndex + endIndex) / 2; if (startIndex < middleIndex) { mergeSort(array, startIndex, middleIndex); } if (middleIndex + 1 < endIndex) { mergeSort(array, middleIndex + 1, endIndex); } // mergeSorted(array, startIndex, middleIndex, endIndex); merge(array, startIndex, middleIndex, endIndex); } } public static void mergeSorted(int[] array, int startIndex1, int endIndex1, int endIndex2) { int[] tempArray = array.clone(); int startIndex2 = endIndex1 + 1; int iterator1 = startIndex1; int iterator2 = startIndex2; for (int i = startIndex1; i <= endIndex2; i++) { int item = Integer.MAX_VALUE; if (iterator1 <= endIndex1) { // no ha llegado al final de la primera mitad item = tempArray[iterator1]; } if (iterator2 <= endIndex2 && tempArray[iterator2] < item) { // no ha llegado al final de la primera mitad y // hay // un item menor ahi item = tempArray[iterator2]; iterator2++; } else { iterator1++; } array[i] = item; } } public static void merge(int arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ int L[] = new int[n1]; int R[] = new int[n2]; /* Copy data to temp arrays */ for (int i = 0; i < n1; ++i) L[i] = arr[l + i]; for (int j = 0; j < n2; ++j) R[j] = arr[m + 1 + j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } public static void mergeSortI(int arr[], int n) { // For current size of subarrays to // be merged curr_size varies from // 1 to n/2 int curr_size; // For picking starting index of // left subarray to be merged int left_start; // Merge subarrays in bottom up // manner. First merge subarrays // of size 1 to create sorted // subarrays of size 2, then merge // subarrays of size 2 to create // sorted subarrays of size 4, and // so on. for (curr_size = 1; curr_size <= n - 1; curr_size = 2 * curr_size) { // Pick starting point of different // subarrays of current size for (left_start = 0; left_start < n - 1; left_start += 2 * curr_size) { // Find ending point of left // subarray. mid+1 is starting // point of right int mid = Math.min(left_start + curr_size - 1, n - 1); int right_end = Math.min(left_start + 2 * curr_size - 1, n - 1); // Merge Subarrays arr[left_start...mid] // & arr[mid+1...right_end] mergeI(arr, left_start, mid, right_end); } } } /* * Function to merge the two haves arr[l..m] and arr[m+1..r] of array arr[] */ static void mergeI(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; /* create temp arrays */ int L[] = new int[n1]; int R[] = new int[n2]; /* * Copy data to temp arrays L[] and R[] */ for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1 + j]; /* * Merge the temp arrays back into arr[l..r] */ i = 0; j = 0; k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* * Copy the remaining elements of L[], if there are any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* * Copy the remaining elements of R[], if there are any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } }