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

Envío 763

Problema 0xcf - Mirando al horizonte

  • Autor: abatesins
  • Fecha: 2020-09-15 11:59:30 UTC (Hace más de 4 años)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 54, in <module>
    view_heights = case(n_arr, arr)
TypeError: 'int' object is not callable
0.042 s 3 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 54, in <module>
    view_heights = case(n_arr, arr)
TypeError: 'int' object is not callable
0.034 s 7 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 54, in <module>
    view_heights = case(n_arr, arr)
TypeError: 'int' object is not callable
0.036 s 7 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 54, in <module>
    view_heights = case(n_arr, arr)
TypeError: 'int' object is not callable
0.03 s 5 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 54, in <module>
    view_heights = case(n_arr, arr)
TypeError: 'int' object is not callable
0.037 s 4 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 54, in <module>
    view_heights = case(n_arr, arr)
TypeError: 'int' object is not callable
0.19 s 39 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 54, in <module>
    view_heights = case(n_arr, arr)
TypeError: 'int' object is not callable
0.134 s 12 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 54, in <module>
    view_heights = case(n_arr, arr)
TypeError: 'int' object is not callable
0.223 s 56 KBi
#9
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 54, in <module>
    view_heights = case(n_arr, arr)
TypeError: 'int' object is not callable
0.152 s 14 KBi
#10
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 54, in <module>
    view_heights = case(n_arr, arr)
TypeError: 'int' object is not callable
0.224 s 55 KBi
Puntos totales: 0 / 100

Código

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 is_root(self):
        return self.parent is None

    def __lt__(self, other):
        return self.value < other.value

def case(n_arr, arr):
    tree = []
    view_heights = []
    
    for idx, val in enumerate(arr[::-1]):
        idx = n_arr - idx - 1
        node = Node(val, idx)
        if len(tree) == 0:
            view_heights.append(-1)
            tree.append(node)
            continue
        else:
            # search parent
            last_node = tree[-1]
            while True:
                if node < last_node:
                    # add as child of last_node
                    node.parent = last_node
                    last_node.children.append(node)
                    view_heights.append(last_node.value)
                    tree.append(node)
                    break
                else:
                    # go up the tree
                    if last_node.is_root():
                        # add node as new root
                        last_node.parent = node
                        node.children.append(last_node)
                        view_heights.append(-1)
                        tree.append(node)
                        break
                    else:
                        last_node = last_node.parent
    return view_heights[::-1]

if __name__ == "__main__":
    num_cases = int(input())
    for case 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}: ' + ' '.join(map(str, view_heights)))