Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.007 s | 2 KBi |
#2 |
Correcto
|
0.005 s | 2 KBi |
#3 |
Correcto
|
0.005 s | 6 KBi |
#4 |
Correcto
|
0.004 s | 0 KBi |
#5 |
Correcto
|
0.007 s | 9 KBi |
#6 |
Correcto
|
0.007 s | 4 KBi |
#7 |
Correcto
|
0.004 s | 2 KBi |
#8 |
Correcto
|
0.005 s | 13 KBi |
#9 |
Correcto
|
0.005 s | 2 KBi |
#10 |
Correcto
|
0.004 s | 0 KBi |
#11 |
Correcto
|
0.006 s | 2 KBi |
#12 |
Correcto
|
0.005 s | 9 KBi |
#13 |
Correcto
|
0.012 s | 2 KBi |
#14 |
Correcto
|
0.009 s | 1 KBi |
#15 |
Correcto
|
0.006 s | 0 KBi |
#16 |
Correcto
|
0.008 s | 10 KBi |
#17 |
Correcto
|
0.007 s | 4 KBi |
#18 |
Correcto
|
0.005 s | 17 KBi |
#19 |
Correcto
|
0.006 s | 2 KBi |
#20 |
Correcto
|
0.007 s | 3 KBi |
#include <bits/stdc++.h> using namespace std; void merge(vector<int> &arr, int l_, int m, int r){ vector<int> left(m-l_+1), rigth(r-m); for(int i=l_, j=0; i<=m; ++i, ++j) left[j] = arr[i]; for(int i=m+1, j=0; i<=r; ++i, ++j) rigth[j] = arr[i]; int i = 0, j = 0, l =l_; while(i < m-l_+1 && j < r-m){ if(left[i] <= rigth[j]) arr[l++] = left[i++]; else arr[l++] = rigth[j++]; } while(i < m-l_+1) arr[l++] = left[i++]; while(j < r-m) arr[l++] = rigth[j++]; } void mergeSort(vector<int> &arr, int l, int r){ if(l >= r) return; else{ int m = l + (r - l)/2; mergeSort(arr, l, m); mergeSort(arr, m+1, r); merge(arr, l, m, r); } } int main(){ int n; cin >> n; vector<int> arr(n); for(int &i: arr) cin >> i; mergeSort(arr, 0, n-1); for(int i: arr) cout << i << " "; return 0; }