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

Envío 1921

Problema 0xdd - Ordenar un arreglo pequeño

  • Autor: ppastram
  • Fecha: 2020-11-10 16:12:50 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.005 s 1 KBi
#2
Correcto
0.006 s 1 KBi
#3
Correcto
0.007 s 1 KBi
#4
Correcto
0.006 s 4 KBi
#5
Correcto
0.006 s 1 KBi
#6
Correcto
0.007 s 1 KBi
#7
Correcto
0.005 s 1 KBi
#8
Correcto
0.005 s 1 KBi
#9
Correcto
0.006 s 1 KBi
#10
Correcto
0.006 s 1 KBi
#11
Correcto
0.01 s 1 KBi
#12
Correcto
0.008 s 1 KBi
#13
Correcto
0.01 s 1 KBi
#14
Correcto
0.007 s 1 KBi
#15
Correcto
0.007 s 1 KBi
#16
Correcto
0.006 s 1 KBi
#17
Correcto
0.017 s 1 KBi
#18
Correcto
0.01 s 1 KBi
#19
Correcto
0.01 s 1 KBi
#20
Correcto
0.013 s 1 KBi
Puntos totales: 100 / 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;

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

    // --- SELECTION SORT --- -> el lado izquiero va quedando ordenando, va agregando el elemento menor de la parte derecha
    /*
    for(int i = 0; i < n-1; i++)
    {
        int min = N;
        for(int j = i; j < n; j++)
        {
            if(a[j] < min)
            {
                min = a[j];
                pos = j;
            }
        }
        if(min != N)
        {
            temp = a[i];
            a[i] = a[pos];
            a[pos] = temp;
        }
    }
    */

    // --- INSERTION SORT --- -> el lado izquiero va quedando ordenando y va atropellando al primero de la derecha para meterlo en su puesto en el lado izq
    for(int next = 1; next < n; next++)
    {
        for(int j = next; a[j-1] > a[j] && j>0; j--)
        {
            swap(a[j-1], a[j]);
        }
    }

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