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

Envío 1266

Problema 0xcf - Mirando al horizonte

  • Autor: EduardoVega
  • Fecha: 2020-10-16 13:27:04 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.002 s 1 KBi
#2
Correcto
0.004 s 15 KBi
#3
Correcto
0.003 s 1 KBi
#4
Correcto
0.005 s 4 KBi
#5
Correcto
0.003 s 1 KBi
#6
Correcto
0.102 s 21 KBi
#7
Correcto
0.074 s 10 KBi
#8
Correcto
0.102 s 9 KBi
#9
Tiempo límite excedido
1.064 s 5 KBi
#10
Tiempo límite excedido
1.056 s 5 KBi
Puntos totales: 80 / 100

Código

#include <stdio.h>
#include <stdlib.h>

int main()
{
  long int cases = 0, size = 0,
  num = 0, mayor = 0, anterior = 0,
  i, j, k;
  long int *array = NULL;
  long int *aux = NULL;
 
  scanf("%li", &cases);
 
  for(i = 0; i < cases; i++)
  {
    scanf("%li", &size);
    array = malloc(sizeof(long int) * size);
    aux = malloc(sizeof(long int) * size);
   
    for(j = 0; j < size; j++)
    {
      scanf("%li", &num);
      array[j] = num;
    }
    
    for(j = size - 1; j >= 0; j--)
    {
      if(array[j] >= mayor)
      {
        mayor = array[j];
        aux[j] = -1;
        anterior = j;
      }
      
      if(array[j] < array[anterior])
      {
        aux[j] = array[anterior];
        anterior = j;
      }
      
      if(array[j] >= array[anterior] && array[j] 
      < mayor)
      {
        while(array[anterior] < mayor && array[j] 
        >= array[anterior])
          anterior++;
        
        aux[j] = array[anterior];
      }
    }
    
    printf("Case #%li:", i + 1);
    for(j = 0; j < size; j++)
      printf(" %li", aux[j]);
    putchar('\n');
    
    mayor = 0;
    free(array);
    free(aux);
  }
}