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

Envío 5323

Problema 0xde - Ordenar un arreglo grande

  • Autor: tille
  • Fecha: 2021-11-08 23:50:49 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.005 s 0 KBi
#2
Correcto
0.005 s 0 KBi
#3
Correcto
0.004 s 0 KBi
#4
Correcto
0.005 s 0 KBi
#5
Correcto
0.005 s 0 KBi
#6
Correcto
0.003 s 0 KBi
#7
Tiempo límite excedido
1.04 s 1 KBi
#8
Tiempo límite excedido
1.073 s 1 KBi
#9
Tiempo límite excedido
1.051 s 3 KBi
#10
Correcto
0.79 s 1 KBi
#11
Tiempo límite excedido
1.051 s 1 KBi
#12
Tiempo límite excedido
1.082 s 4 KBi
#13
Correcto
0.065 s 1 KBi
#14
Correcto
0.054 s 1 KBi
#15
Correcto
0.059 s 1 KBi
#16
Correcto
0.118 s 2 KBi
#17
Correcto
0.122 s 3 KBi
#18
Correcto
0.069 s 1 KBi
#19
Correcto
0.071 s 1 KBi
#20
Tiempo límite excedido
1.084 s 1 KBi
#21
Correcto
0.06 s 5 KBi
#22
Correcto
0.066 s 2 KBi
#23
Correcto
0.072 s 1 KBi
#24
Correcto
0.074 s 1 KBi
#25
Correcto
0.093 s 2 KBi
#26
Correcto
0.09 s 1 KBi
#27
Correcto
0.093 s 1 KBi
Puntos totales: 78 / 100

Código

#include<iostream>
#include<cstdlib>
 
using namespace std;
 
// Swapping two values.
void swap(int *a, int *b)
{
	int temp; 
	temp = *a;
	*a = *b;
	*b = temp;
}
 
// Partitioning the array on the basis of values at high as pivot value.
int Partition(int a[], int low, int high)
{
	int pivot, index, i;
	index = low;
	pivot = high;
 
	// Getting index of the pivot.
	for(i=low; i < high; i++)
	{
		if(a[i] < a[pivot])
		{
			swap(&a[i], &a[index]);
			index++;
		}
	}
	// Swapping value at high and at the index obtained.
	swap(&a[pivot], &a[index]);
 
	return index;
}
 
// Random selection of pivot.
int RandomPivotPartition(int a[], int low, int high)
{
	int pvt, n, temp;
	n = rand();
	// Randomizing the pivot value in the given subpart of array.
	pvt = low + n%(high-low+1);
 
	// Swapping pivot value from high, so pivot value will be taken as a pivot while partitioning.
	swap(&a[high], &a[pvt]);
 
	return Partition(a, low, high);
}
 
int QuickSort(int a[], int low, int high)
{
	int pindex;
	if(low < high)
	{
		// Partitioning array using randomized pivot.
		pindex = RandomPivotPartition(a, low, high);
		// Recursively implementing QuickSort.
		QuickSort(a, low, pindex-1);
		QuickSort(a, pindex+1, high);
	}
	return 0;
}
 
int main()
{
	int n, i;
	cin>>n;
 
	int arr[n];
	for(i = 0; i < n; i++)
	{
		cin>>arr[i];
	}
 
	QuickSort(arr, 0, n-1);
 
	for (i = 0; i < n; i++)
        	cout<< arr[i] << " ";
    cout << endl;
 
	return 0;
}