Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 1 KBi |
#2 |
Correcto
|
0.004 s | 0 KBi |
#3 |
Correcto
|
0.005 s | 1 KBi |
#4 |
Correcto
|
0.006 s | 0 KBi |
#5 |
Correcto
|
0.005 s | 5 KBi |
#6 |
Correcto
|
0.003 s | 0 KBi |
#7 |
Correcto
|
0.069 s | 3 KBi |
#8 |
Correcto
|
0.103 s | 5 KBi |
#9 |
Correcto
|
0.087 s | 3 KBi |
#10 |
Correcto
|
0.113 s | 2 KBi |
#11 |
Correcto
|
0.135 s | 2 KBi |
#12 |
Correcto
|
0.113 s | 2 KBi |
#13 |
Correcto
|
0.122 s | 2 KBi |
#14 |
Correcto
|
0.08 s | 3 KBi |
#15 |
Correcto
|
0.111 s | 2 KBi |
#16 |
Correcto
|
0.138 s | 2 KBi |
#17 |
Correcto
|
0.136 s | 3 KBi |
#18 |
Correcto
|
0.112 s | 2 KBi |
#19 |
Correcto
|
0.123 s | 2 KBi |
#20 |
Correcto
|
0.068 s | 1 KBi |
#21 |
Correcto
|
0.094 s | 2 KBi |
#22 |
Correcto
|
0.101 s | 2 KBi |
#23 |
Correcto
|
0.099 s | 2 KBi |
#24 |
Correcto
|
0.1 s | 2 KBi |
#25 |
Correcto
|
0.093 s | 2 KBi |
#26 |
Correcto
|
0.141 s | 2 KBi |
#27 |
Correcto
|
0.077 s | 2 KBi |
#include <bits/stdc++.h> using namespace std; void merge(int l, int r, int m, vector<int> &arr, vector<int> &temp) { // vector<int> temp = arr; int p1 = l, p2 = m + 1, i; for (int i = l; i <= r; ++i) temp[i] = arr[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, vector<int> &temp) { if (l < r) { int m = l + (r - l) / 2; mergeSort(l, m, arr, temp); mergeSort(m + 1, r, arr, temp); merge(l, r, m, arr, temp); } } int main () { int n; cin >> n; vector<int> arr(n), helper(n); for (auto &num : arr) cin >> num; mergeSort(0, n-1, arr, helper); for (auto x : arr) cout << x << " "; cout << endl; return 0; }