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

Envío 1925

Problema 0xde - Ordenar un arreglo grande

  • Autor: ppastram
  • Fecha: 2020-11-10 20:25:17 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.079 s 64 KBi
#2
Correcto
0.006 s 1 KBi
#3
Correcto
0.006 s 1 KBi
#4
Incorrecto
0.006 s 1 KBi
#5
Correcto
0.005 s 1 KBi
#6
Incorrecto
0.007 s 1 KBi
#7
Incorrecto
0.007 s 1 KBi
#8
Incorrecto
0.005 s 1 KBi
#9
Incorrecto
0.006 s 1 KBi
#10
Incorrecto
0.005 s 1 KBi
#11
Incorrecto
0.007 s 1 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.007 s 1 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.079 s 64 KBi
#14
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.006 s 1 KBi
#15
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.072 s 64 KBi
#16
Incorrecto
0.006 s 1 KBi
#17
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.007 s 1 KBi
#18
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.072 s 64 KBi
#19
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.074 s 64 KBi
#20
Incorrecto
0.006 s 1 KBi
#21
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.073 s 64 KBi
#22
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.074 s 64 KBi
#23
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.077 s 64 KBi
#24
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.006 s 1 KBi
#25
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.007 s 1 KBi
#26
Incorrecto
0.006 s 1 KBi
#27
Incorrecto
0.007 s 1 KBi
Puntos totales: 12 / 100

Código

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <list>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#define forn(a, n) for(int a = 0; a<(int) (n); ++a)
#define rforn(a, n) for(int a = (n)-1; a>=0; --a)
using namespace std;
const int N = 6e5+20;

/*
void partition(int a[], int low, int high)
{
    int pivot = a[high];
    int i = low-1;

    for(int j = low; j < high; j++)
    {
        if(a[j] < pivot)
        {
            i++;
            swap(a[j], a[i]);
        }
    }
}

void quicksort(int a[], int low, int high)
{
    if(low < high)
    {
        int pi = partition(a, low, high);
        quicksort(a, low, pi-1);
        quicksort(a, pi+1, high);
    }
}
*/

void merge(int a[], int l, int m, int r)
{
    int n1 = m-l+1;
    int n2 = r-m;
    int L [51000];
    int R [51000];

    for(int i = 0; i < n1; i++) L[i] = a[l+i];
    for(int i = 0; i < n2; i++) R[i] = a[m + 1 + i]; 

    int i = 0;
    int j = 0;
    int k = l;

    while(i<n1 && j<n2)
    {
        if(L[i] <= R[j])
        {
            a[k] = L[i];
            i++;
        }
        else
        {
            a[k] = R[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        a[k] = L[i];
        i++;
        k++;
    }
    while (j < n2)
    {
        a[k] = R[i];
        j++;
        k++;
    }
}

void mergeSort(int a[], int l, int r)
{
    if(l < r)
    {
        int m = l + (r-1)/2;
        mergeSort(a, l, m);
        mergeSort(a, m+1, r);
        merge(a, l, m, r);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, pos, temp, este, low, high;
    cin>>n;
    int a [1001];
    //vector <int> a;
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
        //cin>>este;
       //a.push_back(este);
    }
    

    // --- QUICK SORT --- -> ordena entre menor y mayor de pivot, luego ordena en cada mitad lo menor y lo mayor de nuevos pivots
    /*
    low = 0;
    high = n-1;
    quicksort(a, low, high);
    */


    // --- MERGE SORT --- -> parte en mitades, después cada mitad la parte en mitas. al final arma a partir del menor de cada mitad
    mergeSort(a, 0, n-1);

    for(int i = 0; i < n; i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
}