QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#874345#3445. Numbers On a Treefernandes_queilaWA 85ms48024kbJava211.7kb2025-01-28 02:48:122025-01-28 02:48:13

Judging History

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

  • [2025-01-28 02:48:13]
  • 评测
  • 测评结果:WA
  • 用时:85ms
  • 内存:48024kb
  • [2025-01-28 02:48:12]
  • 提交

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[] currentLabel = {1};
        return buildTreeRecursively(height, currentLabel);
    }

    private static TreeNode buildTreeRecursively(int height, int[] currentLabel) {
        if (height < 0) {
            return null;
        }

        TreeNode rightChild = buildTreeRecursively(height - 1, currentLabel);
        TreeNode leftChild = buildTreeRecursively(height - 1, currentLabel);

        TreeNode node = new TreeNode(currentLabel[0]);
        currentLabel[0]++;

        node.left = leftChild;
        node.right = rightChild;

        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: 85ms
memory: 48024kb

input:

3 LR

output:

10

result:

wrong answer 1st lines differ - expected: '11', found: '10'