AT_abc415_c [ABC415C] Mixture
Description
There are $ N $ types of chemicals $ 1,2,\dots,N $ . Your goal is to create a state where all of them are mixed.
You are given a string $ S $ of length $ 2^N-1 $ consisting of `0` and `1`, which represents the following information:
- First, define state $ i $ ( $ 1 \le i \le 2^N-1 $ ) where one or more types of chemicals are mixed as follows:
- When the $ k $ -th digit ( $ 1 \le k \le N $ ) from the bottom in the binary representation of $ i $ is $ 1 $ , and only then, chemical $ k $ is included.
- For example, $ 13 $ in binary is $ 1101_{(2)} $ , so state $ 13 $ represents a state where chemicals $ 1,3,4 $ are mixed.
- When the $ i $ -th character of $ S $ is `0`, state $ i $ is **safe**.
- When the $ i $ -th character of $ S $ is `1`, state $ i $ is **dangerous**.
You mix chemicals using the following operation:
- First, prepare an empty bottle.
- Next, repeat the following:
- Choose one type of chemical that has not yet been poured into the bottle and pour it into the bottle.
- At this time, the chemicals mixed in the bottle must not be in a dangerous state.
Determine whether this operation can create a state where all chemicals are mixed.
You are given $ T $ test cases; solve each of them.
Input Format
The input is given from Standard Input in the following format:
> $ T $ $ \mathrm{case}_1 $ $ \mathrm{case}_2 $ $ \vdots $ $ \mathrm{case}_T $
$ \mathrm{case}_i $ represents the $ i $ -th test case. Each test case is given in the following format:
> $ N $ $ S $
Output Format
Output $ T $ lines. The $ i $ -th line should contain the answer for the $ i $ -th test case.
For each test case, if it is possible to create a state where all chemicals are mixed, print `Yes`; otherwise, print `No`.
Explanation/Hint
### Sample Explanation 1
This input contains five test cases.
The $ 1 $ st case is as follows:
- There are three types of chemicals.
- Only state $ 3 $ where chemicals $ 1,2 $ are mixed is dangerous, and the other states are safe.
- For example, you can create a state where all chemicals are mixed with the following procedure:
- First, pour chemical $ 2 $ into the bottle. Only chemical $ 2 $ is mixed in the bottle, which is state $ 2 $ , so it is safe.
- Next, pour chemical $ 3 $ into the bottle. Chemicals $ 2,3 $ are mixed in the bottle, which is state $ 6 $ , so it is safe.
- Finally, pour chemical $ 1 $ into the bottle. Chemicals $ 1,2,3 $ are mixed in the bottle, which is state $ 7 $ , so it is safe.
The $ 2 $ nd case is as follows:
- There are three types of chemicals.
- State $ 3 $ where chemicals $ 1,2 $ are mixed, state $ 5 $ where chemicals $ 1,3 $ are mixed, and state $ 6 $ where chemicals $ 2,3 $ are mixed are dangerous, and the other states are safe.
- For this case, it is impossible to create a state where all chemicals are mixed.
The $ 3 $ rd case is as follows:
- There is one type of chemical.
- Since state $ 1 $ where only chemical $ 1 $ is mixed is dangerous, it is impossible to create a state where all chemicals are mixed.
### Constraints
- $ T $ is an integer between $ 1 $ and $ 40000 $ , inclusive.
- $ N $ is an integer between $ 1 $ and $ 18 $ , inclusive.
- $ S $ is a string of length $ 2^N-1 $ consisting of `0` and `1`.
- The sum of $ |S| = 2^N-1 $ in each input does not exceed $ 5 \times 10^5 $ .