#P1087. [NOIP 2004 普及组] FBI 树

    ID: 87 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>字符串搜索树形结构2004递归NOIp 普及组构造

[NOIP 2004 普及组] FBI 树

Description

We can divide strings composed of 0 and 1 into three categories: an all-0 string is called a B string, an all-1 string is called an I string, and a string that contains both 0 and 1 is called an F string.

An FBI tree is a binary tree whose node types are F, B, and I. Given a binary string SS of length 2N2^N, an FBI tree TT can be constructed recursively as follows:

  1. Let RR be the root of TT, and set its type to be the same as the type of SS.
  2. If the length of SS is greater than 1, split SS in the middle into equal-length left and right substrings S1S_1 and S2S_2. Construct the left subtree T1T_1 of RR from S1S_1, and the right subtree T2T_2 of RR from S2S_2.

Given a binary string of length 2N2^N, construct an FBI tree using the method above and output its postorder traversal sequence.

Input Format

The first line contains an integer N(0N10)N (0 \le N \le 10).
The second line contains a binary string of length 2N2^N.

Output Format

A single string, i.e., the postorder traversal sequence of the FBI tree.

3
10001011

IBFBBBFIBFIIIFF

Hint

For 40% of the testdata, N2N \le 2.
For all the testdata, N10N \le 10.
This is the 3rd problem of NOIP 2004 Junior.

Translated by ChatGPT 5