QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#874516 | #3445. Numbers On a Tree | fernandes_queila | WA | 9ms | 8832kb | Python3 | 1.1kb | 2025-01-28 10:06:26 | 2025-01-28 10:06:28 |
Judging History
answer
class TreeNode:
def __init__(self, label):
self.label = label
self.left = None
self.right = None
def build_tree(height):
total_nodes = (2 ** (height + 1)) - 1
current_label = [total_nodes]
return build_tree_recursively(height, current_label)
def build_tree_recursively(height, current_label):
if height < 0:
return None
node = TreeNode(current_label[0])
current_label[0] -= 1
node.right = build_tree_recursively(height - 1, current_label)
node.left = build_tree_recursively(height - 1, current_label)
return node
def search_node_in_tree(root, road):
current = root
for move in road:
if move.lower() == 'l':
current = current.left
elif move.lower() == 'r':
current = current.right
if current is None:
raise ValueError("Invalid path")
return current.label
def main():
line = input().strip()
parts = line.split()
height = int(parts[0])
road = parts[1] if len(parts) > 1 else ""
root = build_tree(height)
result = search_node_in_tree(root, road)
print(result)
main()
詳細信息
Test #1:
score: 0
Wrong Answer
time: 9ms
memory: 8832kb
input:
3 LR
output:
6
result:
wrong answer 1st lines differ - expected: '11', found: '6'