Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 0 KBi |
#2 |
Correcto
|
0.004 s | 3 KBi |
#3 |
Correcto
|
0.004 s | 2 KBi |
#4 |
Correcto
|
0.007 s | 1 KBi |
#5 |
Correcto
|
0.004 s | 0 KBi |
#6 |
Correcto
|
0.004 s | 18 KBi |
#7 |
Correcto
|
0.026 s | 1 KBi |
#8 |
Correcto
|
0.025 s | 1 KBi |
#9 |
Correcto
|
0.036 s | 62 KBi |
#10 |
Correcto
|
0.039 s | 2 KBi |
#11 |
Correcto
|
0.043 s | 2 KBi |
#12 |
Correcto
|
0.039 s | 2 KBi |
#13 |
Correcto
|
0.038 s | 2 KBi |
#14 |
Correcto
|
0.044 s | 3 KBi |
#15 |
Correcto
|
0.03 s | 2 KBi |
#16 |
Correcto
|
0.077 s | 3 KBi |
#17 |
Correcto
|
0.069 s | 3 KBi |
#18 |
Correcto
|
0.04 s | 2 KBi |
#19 |
Correcto
|
0.031 s | 2 KBi |
#20 |
Correcto
|
0.028 s | 2 KBi |
#21 |
Correcto
|
0.037 s | 2 KBi |
#22 |
Correcto
|
0.044 s | 3 KBi |
#23 |
Correcto
|
0.041 s | 3 KBi |
#24 |
Correcto
|
0.046 s | 2 KBi |
#25 |
Correcto
|
0.042 s | 2 KBi |
#26 |
Correcto
|
0.042 s | 16 KBi |
#27 |
Correcto
|
0.046 s | 2 KBi |
#include <iostream> using namespace std; void display(int *array, int size) { for(int i = 0; i<size; i++) cout << array[i] << " "; cout << endl; } void merge(int *a, int l, int m, int r) { int i, j, k, nl, nr; //size of left and right sub-arrays nl = m-l+1; nr = r-m; int larr[nl], rarr[nr]; //fill left and right sub-arrays for(i = 0; i<nl; i++) larr[i] = a[l+i]; for(j = 0; j<nr; j++) rarr[j] = a[m+1+j]; i = 0; j = 0; k = l; //marge temp arrays to real array while(i < nl && j<nr) { if(larr[i] <= rarr[j]) { a[k] = larr[i]; i++; } else { a[k] = rarr[j]; j++; } k++; } while(i<nl) { //extra element in left array a[k] = larr[i]; i++; k++; } while(j<nr) { //extra element in right array a[k] = rarr[j]; j++; k++; } } void mergeSort(int a[], int l, int r) { int m; if (l < r) { int m = l+(r-l)/2; mergeSort(a, l, m); mergeSort(a, m+1, r); merge(a, l, m, r); } } int main() { int N; cin >> N; int a[N]; for (int i = 0; i < N; i++) { cin >> a[i]; } mergeSort(a, 0, N-1); display(a, N); return 0; }