Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.042 s | 7 KBi |
#2 |
Correcto
|
0.034 s | 3 KBi |
#3 |
Correcto
|
0.03 s | 3 KBi |
#4 |
Correcto
|
0.028 s | 3 KBi |
#5 |
Correcto
|
0.031 s | 3 KBi |
#6 |
Tiempo límite excedido
|
0.761 s | 59 KBi |
#7 |
Tiempo límite excedido
|
0.877 s | 73 KBi |
#8 |
Tiempo límite excedido
|
1.043 s | 78 KBi |
#9 |
Tiempo límite excedido
|
1.025 s | 75 KBi |
#10 |
Tiempo límite excedido
|
1.043 s | 87 KBi |
class Node(object): def __init__(self, value, idx): self.parent = None self.children = [] self.value = value # height self.idx = idx # in the original array def adopt(parent, child): parent.children.append(child) child.parent = parent def case(n_arr, arr): tree = [] view_heights = [-1] * n_arr for idx, val in enumerate(arr[::-1]): idx = n_arr - idx - 1 node = Node(val, idx) if len(tree) == 0: tree.append(node) continue else: # search parent last_node = tree[-1] while True: if node.value < last_node.value: # add as child of last_node adopt(last_node, node) view_heights[idx] += last_node.value + 1 tree.append(node) break else: # go up the tree if last_node.parent is None: # add node as new root adopt(node, last_node) tree.append(node) break else: last_node = last_node.parent 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)))