QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#874514 | #3445. Numbers On a Tree | fernandes_queila | WA | 79ms | 48052kb | Java21 | 1.7kb | 2025-01-28 10:03:01 | 2025-01-28 10:03:01 |
Judging History
answer
import java.util.Scanner;
public class BinaryTreeLabel {
static class TreeNode {
int label;
TreeNode left, right;
TreeNode(int label) {
this.label = label;
this.left = this.right = null;
}
}
public static TreeNode buildTree(int height) {
int totalNodes = (1 << (height + 1)) - 1;
int[] currentLabel = {totalNodes};
return buildTreeRecursively(height, currentLabel);
}
private static TreeNode buildTreeRecursively(int height, int[] currentLabel) {
if (height < 0) {
return null;
}
TreeNode node = new TreeNode(currentLabel[0]--);
node.right = buildTreeRecursively(height - 1, currentLabel);
node.left = buildTreeRecursively(height - 1, currentLabel);
return node;
}
public static int findLabel(TreeNode root, String path) {
TreeNode currentNode = root;
for (int i = 0; i < path.length(); i++) {
if (path.charAt(i) == 'L') {
currentNode = currentNode.left;
} else if (path.charAt(i) == 'R') {
currentNode = currentNode.right;
}
}
return currentNode.label;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String inputLine = scanner.nextLine().strip();
String[] parts = inputLine.split(" ");
int height = Integer.parseInt(parts[0]);
String path = parts.length > 1 ? parts[1] : "";
TreeNode root = buildTree(height);
int result = findLabel(root, path);
System.out.println(result);
scanner.close();
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 79ms
memory: 48052kb
input:
3 LR
output:
6
result:
wrong answer 1st lines differ - expected: '11', found: '6'