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