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

Envío 3629

Problema 0xcf - Mirando al horizonte

  • Autor: jocarmp08
  • Fecha: 2021-04-04 06:32:48 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.028 s 7 KBi
#2
Incorrecto
0.035 s 3 KBi
#3
Correcto
0.025 s 3 KBi
#4
Correcto
0.023 s 3 KBi
#5
Correcto
0.028 s 3 KBi
#6
Incorrecto
0.345 s 43 KBi
#7
Correcto
0.354 s 43 KBi
#8
Correcto
0.467 s 57 KBi
#9
Incorrecto
0.421 s 47 KBi
#10
Incorrecto
0.475 s 58 KBi
Puntos totales: 60 / 100

Código

from collections import deque


def looking_to_the_horizon(array, n):
    tallest_and_nearest_building_height = -1
    prev_building_height = array[n - 1]

    stack = deque(maxlen=n)
    stack.append(tallest_and_nearest_building_height)

    for i in reversed(range(n - 1)):
        current_building_height = array[i]

        if current_building_height < prev_building_height:
            tallest_and_nearest_building_height = prev_building_height
            stack.append(tallest_and_nearest_building_height)
        
        elif current_building_height > prev_building_height and current_building_height > tallest_and_nearest_building_height:
            tallest_and_nearest_building_height = current_building_height
            stack.append(-1)

        else:
            if current_building_height == tallest_and_nearest_building_height:
                stack.append(-1)
            else:
                stack.append(tallest_and_nearest_building_height)
        
        prev_building_height = current_building_height

    return list(reversed(stack))


number_of_cases = int(input())
for i in range(number_of_cases):
    array_size = int(input())
    array = [int(x) for x in input().split()]
    print("Case #{0}: {1}".format(
        i + 1, ' '.join(map(str, looking_to_the_horizon(array, array_size)))))