#T425. FBI树

FBI树

Description

Strings composed of "0" and "1" can be classified into three categories: strings consisting entirely of "0" are called B strings, strings consisting entirely of "1" are called I strings, and strings containing both "0" and "1" are called F strings.

The FBI tree is a type of binary tree[1], and its node types also include F nodes, B nodes, and I nodes. A "01" string S of length 2N can be used to construct an FBI tree T using the following recursive method:

1) The root node of T is R, and its type is the same as the type of the string S;

2) If the length of the string S is greater than 1, split the string S from the middle into two equal-length substrings, the left substring S1 and the right substring S2; construct the left subtree T1 of R from the left substring S1, and construct the right subtree T2 of R from the right substring S2.

Given a "01" string of length 2N, please use the above construction method to build an FBI tree and output its post-order traversal[2] sequence.

[1] Binary tree: A binary tree is a finite set of nodes, which is either empty or consists of a root node and two disjoint binary trees. These two disjoint binary trees are called the left subtree and right subtree of the root node, respectively.

[2] Post-order traversal: Post-order traversal is a method of depth-first traversal of a binary tree. Its recursive definition is: first traverse the left subtree in post-order, then traverse the right subtree in post-order, and finally visit the root node.

Input Format

The first line of input is an integer N (0 <= N <= 10), and the second line is a "01" string of length 2N.

Output Format

The output consists of only one line, containing a single string, which is the post-order traversal sequence of the FBI tree.

3
10001011
IBFBBBFIBFIIIFF

Hint

For 40% of the data, N <= 2;

For all data, N <= 10.

Source

CodesOnline