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

Envío 3631

Problema 0xcf - Mirando al horizonte

  • Autor: jocarmp08
  • Fecha: 2021-04-04 07:05:59 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.038 s 3 KBi
#2
Correcto
0.036 s 3 KBi
#3
Correcto
0.023 s 3 KBi
#4
Correcto
0.025 s 3 KBi
#5
Correcto
0.029 s 3 KBi
#6
Correcto
0.732 s 44 KBi
#7
Correcto
0.707 s 43 KBi
#8
Correcto
0.69 s 71 KBi
#9
Correcto
0.803 s 46 KBi
#10
Correcto
0.814 s 59 KBi
Puntos totales: 100 / 100

Código

from collections import deque


def looking_to_the_horizon(array, n):
    result = [-1 for _ in range(n)]
    stack = deque(maxlen=n)

    for current_building_index, current_building_height in enumerate(array):
        while len(stack) > 0:
            # Get previous building info from the stack
            prev_building_index, prev_building_height = stack[len(stack) - 1]
            if prev_building_height < current_building_height:
                # If previous building height is lower than current building height, update results
                result[prev_building_index] = current_building_height
                stack.pop()
            else:
                break

        # Push the current building info to the stack
        stack.append((current_building_index, current_building_height))

    return result


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)))))