Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.038 s | 3 KBi |
#2 |
Correcto
|
0.025 s | 3 KBi |
#3 |
Correcto
|
0.039 s | 3 KBi |
#4 |
Correcto
|
0.035 s | 3 KBi |
#5 |
Correcto
|
0.034 s | 3 KBi |
#6 |
Tiempo límite excedido
|
1.028 s | 39 KBi |
#7 |
Tiempo límite excedido
|
1.069 s | 12 KBi |
#8 |
Tiempo límite excedido
|
1.058 s | 53 KBi |
#9 |
Tiempo límite excedido
|
1.062 s | 13 KBi |
#10 |
Tiempo límite excedido
|
1.051 s | 58 KBi |
from collections import deque cases = int(input()) for case in range(cases): n = input() buildings = [int(v) for v in input().split(" ")] result = [] stack = deque([buildings[-1]]) for building in buildings[::-1]: # print(f"building {building}, stack {stack}, top {stack[-1]}", building, stack) if len(stack) > 0 and building < stack[-1]: result.insert(0, stack[-1]) stack.append(building) else: while len(stack) > 0 and building >= stack[-1]: stack.pop() if len(stack) > 0 and building < stack[-1]: result.insert(0, stack[-1]) if len(stack) == 0: result.insert(0, -1) stack.append(building) # print(f"result: {result}") str_result = "" for building in result: str_result += str(building) + " " print(f"Case #{case+1}: {str_result}") """ 3 10 4 2 1 6 3 2 5 3 1 4 3 1 1 2 6 3 3 2 2 1 1 """ """ 1 3 1 1 2 1 10 4 2 1 6 3 2 5 3 1 4 """