P14855 [CodeChef] BALREV
普及-
题目描述

Chef is given a binary string A of length N. He can perform the following operation on A any number of times:
Choose L and R (1 ≤ L ≤ R ≤ N), such that, in the [substring] A[L,R], the number of 1s is equal to the number of 0s and reverse the substring A[L,R].

Find the lexicographically smallest string that Chef can obtain after performing the above operation any (possibly zero) number of times on A.

String X is lexicographically smaller than string Y, if either of the following satisfies:
X is a prefix of Y and $X \neq Y$.
There exists an index i such that X_{i} < Y_{i} and $X_{j} = Y_{j}, \forall j$ such that 1 ≤ j < i.

------ Input Format ------

  • First line will contain T, the number of test cases. Then the test cases follow. Each test case contains two lines.
  • The first line contains the integer N, the length of the binary string.
  • The second line contains the binary string A.

------ Output Format ------

For each test case, print the lexicographically smallest binary string that can be obtained after performing the operation any (possibly zero) number of times.

------ Constraints ------

$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{5}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.

----- Sample Input 1 ------
2
5
01100
4
0000

----- Sample Output 1 ------
00011
0000
----- explanation 1 ------
Test Case $1$: Chef can choose $L = 2$ and $R=5$. The chosen substring, $A[2,5] = 1100$. On reversing this, we get $0011$. Thus, the final string is $A = 00011$. Note that this is the lexicographically smallest string possible.

Test Case $2$: Since the string is already lexicographically minimum, Chef does not need to apply any operation.

输入格式

见题面

输出格式

见题面

样例输入
2 5 01100 4 0000
样例输出
00011 0000