Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.036 s | 3 KBi |
#2 |
Correcto
|
0.029 s | 3 KBi |
#3 |
Correcto
|
0.03 s | 3 KBi |
#4 |
Correcto
|
0.026 s | 3 KBi |
#5 |
Correcto
|
0.042 s | 7 KBi |
#6 |
Correcto
|
0.666 s | 47 KBi |
#7 |
Correcto
|
0.525 s | 46 KBi |
#8 |
Correcto
|
0.542 s | 58 KBi |
#9 |
Correcto
|
0.594 s | 52 KBi |
#10 |
Correcto
|
0.503 s | 61 KBi |
def case(n_arr, arr): stack = [-1] * n_arr stack_ptr = -1 # because pop() and append() are expensive as sh*t view_heights = [-1] * n_arr for idx, height in enumerate(reversed(arr)): idx = n_arr - idx - 1 # reverse index #while len(stack) > 0: while stack_ptr >= 0: #lst_height = stack[-1] lst_height = stack[stack_ptr] if height >= lst_height: #_ = stack.pop() stack_ptr -= 1 else: view_heights[idx] = lst_height #stack.append(height) stack_ptr += 1 stack[stack_ptr] = height break else: #stack.append(height) stack_ptr += 1 stack[stack_ptr] = height view_heights[idx] = -1 return view_heights if __name__ == "__main__": num_cases = int(input()) for case_nr in range(1, num_cases+1): n_arr = int(input()) arr = list(map(int, input().split(' '))) view_heights = case(n_arr, arr) print(f'Case #{case_nr}: ' + ' '.join(map(str, view_heights)))