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

Envío 1267

Problema 0xcf - Mirando al horizonte

  • Autor: EduardoVega
  • Fecha: 2020-10-16 13:42:34 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.003 s 1 KBi
#2
Incorrecto
0.003 s 1 KBi
#3
Correcto
0.004 s 18 KBi
#4
Correcto
0.004 s 1 KBi
#5
Correcto
0.002 s 1 KBi
#6
Incorrecto
0.086 s 18 KBi
#7
Correcto
0.071 s 9 KBi
#8
Correcto
0.105 s 9 KBi
#9
Tiempo límite excedido
1.082 s 6 KBi
#10
Tiempo límite excedido
1.081 s 6 KBi
Puntos totales: 60 / 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;
        continue;
      }
      
      if(array[j] < array[anterior])
      {
        aux[j] = array[anterior];
        anterior = j;
        continue;
      }
      
      while(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);
  }
}