QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#873892 | #3445. Numbers On a Tree | fernandes_queila | TL | 10ms | 8832kb | Python3 | 1.2kb | 2025-01-27 07:13:41 | 2025-01-27 07:13:41 |
Judging History
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