█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 5318

Problema 0xde - Ordenar un arreglo grande

  • Autor: tille
  • Fecha: 2021-11-08 23:22:07 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.003 s 0 KBi
#2
Correcto
0.005 s 0 KBi
#3
Correcto
0.005 s 0 KBi
#4
Correcto
0.004 s 0 KBi
#5
Correcto
0.004 s 19 KBi
#6
Correcto
0.003 s 2 KBi
#7
Tiempo límite excedido
1.044 s 9 KBi
#8
Tiempo límite excedido
1.076 s 8 KBi
#9
Tiempo límite excedido
1.071 s 8 KBi
#10
Tiempo límite excedido
1.028 s 11 KBi
#11
Tiempo límite excedido
1.076 s 8 KBi
#12
Tiempo límite excedido
1.063 s 8 KBi
#13
Tiempo límite excedido
1.09 s 17 KBi
#14
Tiempo límite excedido
1.045 s 20 KBi
#15
Tiempo límite excedido
1.069 s 8 KBi
#16
Tiempo límite excedido
1.027 s 8 KBi
#17
Tiempo límite excedido
1.033 s 8 KBi
#18
Tiempo límite excedido
1.028 s 8 KBi
#19
Tiempo límite excedido
1.02 s 9 KBi
#20
Tiempo límite excedido
1.042 s 12 KBi
#21
Tiempo límite excedido
1.058 s 8 KBi
#22
Tiempo límite excedido
1.099 s 8 KBi
#23
Tiempo límite excedido
1.059 s 8 KBi
#24
Tiempo límite excedido
1.082 s 8 KBi
#25
Tiempo límite excedido
1.076 s 8 KBi
#26
Tiempo límite excedido
1.043 s 8 KBi
#27
Tiempo límite excedido
1.045 s 8 KBi
Puntos totales: 23 / 100

Código

#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;
}