QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#873892#3445. Numbers On a Treefernandes_queilaTL 10ms8832kbPython31.2kb2025-01-27 07:13:412025-01-27 07:13:41

Judging History

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

  • [2025-01-27 07:13:41]
  • 评测
  • 测评结果:TL
  • 用时:10ms
  • 内存:8832kb
  • [2025-01-27 07:13:41]
  • 提交

answer

class TreeNode:
    def __init__(self, value):
        self.value = value
        self.left = None
        self.right = None
        self.height = 1

class AVLTree:
    def __init__(self):
        self.root = None

    def construct_avl(self, height):
        # Cria uma \xe1rvore AVL completa com base na altura
        total_nodes = (1 << (height + 1)) - 1
        self.root = self._build_tree(1, total_nodes)

    def _build_tree(self, start, end):
        if start > end:
            return None
        mid = (start + end) // 2
        node = TreeNode(mid)
        node.left = self._build_tree(start, mid - 1)
        node.right = self._build_tree(mid + 1, end)
        return node

    def find_node_label(self, height, path):
        cur = 1
        for c in path:
            cur = cur * 2 + (c == 'R')
        total_nodes = (1 << (height + 1)) - 1
        return total_nodes - cur + 1

if __name__ == "__main__":
    import sys
    input = sys.stdin.read
    data = input().strip().split()

    height = int(data[0])  # Altura
    path = data[1] if len(data) > 1 else "" 

    avl_tree = AVLTree()
    avl_tree.construct_avl(height)
    result = avl_tree.find_node_label(height, path)
    print(result)

詳細信息

Test #1:

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

input:

3 LR

output:

11

result:

ok single line: '11'

Test #2:

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

input:

3 RRL

output:

2

result:

ok single line: '2'

Test #3:

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

input:

2

output:

7

result:

ok single line: '7'

Test #4:

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

input:

3 LRL

output:

6

result:

ok single line: '6'

Test #5:

score: -100
Time Limit Exceeded

input:

26 RRLLLLRRRL

output:


result: