QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#874567#3445. Numbers On a Treefernandes_queilaTL 12ms8960kbPython31.1kb2025-01-28 11:07:262025-01-28 11:07:35

Judging History

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

  • [2025-01-28 11:07:35]
  • 评测
  • 测评结果:TL
  • 用时:12ms
  • 内存:8960kb
  • [2025-01-28 11:07: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(height, road=""):
    root = (2 ** (height + 1)) - 1
    if not road:
        return root

    label = root
    local = 0

    for move in road:
        if move.lower() == 'l':  
            local = 2 * local + 1
        elif move.lower() == 'r':
            local = 2 * local + 2

    label -= local
    return 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)  
    print(search_node(height, road))

main()

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 8832kb

input:

3 LR

output:

11

result:

ok single line: '11'

Test #2:

score: 0
Accepted
time: 12ms
memory: 8832kb

input:

3 RRL

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 11ms
memory: 8960kb

input:

2

output:

7

result:

ok single line: '7'

Test #4:

score: 0
Accepted
time: 10ms
memory: 8832kb

input:

3 LRL

output:

6

result:

ok single line: '6'

Test #5:

score: -100
Time Limit Exceeded

input:

26 RRLLLLRRRL

output:


result: