QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#874516#3445. Numbers On a Treefernandes_queilaWA 9ms8832kbPython31.1kb2025-01-28 10:06:262025-01-28 10:06:28

Judging History

你现在查看的是最新测评结果

  • [2025-01-28 10:06:28]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:8832kb
  • [2025-01-28 10:06:26]
  • 提交

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()

Details

Tip: Click on the bar to expand more detailed information

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'