1369B.md (2469B)
1 Source: https://codeforces.com/problemset/problem/1369/B 2 3 B. AccurateLee 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way... 22 23 The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s). 24 25 In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing. 26 27 Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner. 28 29 Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves. 30 31 Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i \lt y_i$. 32 33 Input 34 35 The first line contains the integer $t$ ($1 \le t \le 10^4$) — the number of test cases. 36 37 Next $2t$ lines contain test cases — one per two lines. 38 39 The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$) — the length of the string $s$. 40 41 The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones. 42 43 It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$. 44 45 Output 46 47 Print $t$ answers — one per test case. 48 49 The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero). 50 51 Example 52 53 Input 54 55 ``` 56 5 57 10 58 0001111111 59 4 60 0101 61 8 62 11001101 63 10 64 1110000000 65 1 66 1 67 ``` 68 69 Output 70 71 ``` 72 0001111111 73 001 74 01 75 0 76 1 77 ``` 78 79 Note 80 81 In the first test case, Lee can't perform any moves. 82 83 In the second test case, Lee should erase $s_2$. 84 85 In the third test case, Lee can make moves, for example, in the following order: 11001101 $\rightarrow$ 1100101 $\rightarrow$ 110101 $\rightarrow$ 10101 $\rightarrow$ 1101 $\rightarrow$ 101 $\rightarrow$ 01.