QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#874517 | #3445. Numbers On a Tree | fernandes_queila | TL | 11ms | 8960kb | Python3 | 1.1kb | 2025-01-28 10:10:18 | 2025-01-28 10:10:18 |
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(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: 9ms
memory: 8832kb
input:
3 LR
output:
11
result:
ok single line: '11'
Test #2:
score: 0
Accepted
time: 10ms
memory: 8832kb
input:
3 RRL
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 8ms
memory: 8832kb
input:
2
output:
7
result:
ok single line: '7'
Test #4:
score: 0
Accepted
time: 11ms
memory: 8960kb
input:
3 LRL
output:
6
result:
ok single line: '6'
Test #5:
score: -100
Time Limit Exceeded
input:
26 RRLLLLRRRL