全WA,样例都没过,但是在自己机子上样例正确且在Acwing上面能够AC
查看原帖
全WA,样例都没过,但是在自己机子上样例正确且在Acwing上面能够AC
493638
隐公元年楼主2022/2/2 23:08
s = int(input())
n = input()


class Node:
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None
        self.cls = None
        if val:
            if set(list(val)) == {'1'}:
                self.cls = 'I'
            elif set(list(val)) == {'0'}:
                self.cls = 'B'
            else:
                self.cls = 'F'
        else:
            pass


class FBI:
    def __init__(self, val):
        self.root = Node(val)

        def rec(root, string):
            if len(string) <= 1:
                return
            root.left = Node(string[:len(string) // 2])
            root.right = Node(string[len(string) // 2:])

            rec(root.left, string[:len(string) // 2])

            rec(root.right, string[len(string) // 2:])

        rec(self.root, val)

    def getAns(self):
        ans = ''

        def rec(root):
            nonlocal ans
            if not root:
                return
            rec(root.left)
            rec(root.right)
            ans += root.cls

        rec(self.root)
        return ans


A = FBI(n)
print(A.getAns())
2022/2/2 23:08
加载中...