#P8407. Parenthesis Selection
Parenthesis Selection
Parenthesis Selection
Dr. Juraj has discovered a new kind of fundamental particle called a parenthesision, which can exist in one of two states: open or close. Using his particle accelerator, he created an ensemble of sequences, each consisting of particles. These particles are organized into pairs — every two consecutive particles form a pair. Note that within a pair the two particles (each representing a bracket) may be in different states, or they may be identical (both open or both close). When a sequence is observed, one particle from each pair will collapse into a definite state (either '(' for open or ')' for close).
The problem is as follows: For each of the sequences, determine whether it is possible to select exactly one bracket from each of the pairs such that the resulting sequence (of length ) is a valid parentheses sequence. A sequence is valid if it is empty, or if it can be written in the form ( (A) ) or ( AB ), where both (A) and (B) are valid sequences.
If a valid selection exists, you must output one way to choose from each pair so that the resulting sequence is valid. In the output, for each pair, output a '1' if you select the first bracket (i.e. the one at odd index) or '2' if you select the second bracket (i.e. the one at even index).
inputFormat
The input begins with an integer , the number of test cases. For each test case, the first line contains an integer , indicating that there are pairs (i.e. the sequence length is ). The following line contains a string of length , consisting solely of the characters '(' and ')'. The -th pair consists of the characters and .
outputFormat
For each test case, if there exists a valid selection, output two lines. On the first line, print “YES”. On the second line, print a string of length where the -th character is '1' if you chose the first bracket of the -th pair, or '2' if you chose the second bracket. If no valid selection exists, simply output a single line with “NO”.
sample
1
4
()))((()
YES
1112
</p>