Codeforces Round 876 (Div. 2) |
---|
Finished |
You have a sequence $$$a_1, a_2, \ldots, a_n$$$ of length $$$n$$$, each element of which is either $$$0$$$ or $$$1$$$, and a sequence $$$b$$$, which is initially empty.
You are going to perform $$$n$$$ operations. On each of them you will increase the length of $$$b$$$ by $$$1$$$.
You can find examples of operations in the Notes section.
Determine if there exists a sequence of operations that makes $$$b$$$ equal to $$$a$$$. If such sequence of operations exists, find it.
Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the sequence $$$a$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$) — the sequence $$$a$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case:
451 1 0 0 01130 1 161 0 0 1 1 0
YES 0 0 2 1 3 NO NO YES 0 1 0 2 4 2
In the first test case,
Hence, sequence $$$b$$$ changes in the following way: $$$[\,]$$$ $$$\xrightarrow{p \, = \, 0}$$$ $$$[\, \underline{0} \,]$$$ $$$\xrightarrow{p \, = \, 0}$$$ $$$[\, \underline{0}, 0 \,]$$$ $$$\xrightarrow{p \, = \, 2}$$$ $$$[\, 1, 1, \underline{0} \,]$$$ $$$\xrightarrow{p \, = \, 1}$$$ $$$[\, 0, \underline{0}, 1, 0 \,]$$$ $$$\xrightarrow{p \, = \, 3}$$$ $$$[\, 1, 1, 0, \underline{0}, 0 \,]$$$. In the end the sequence $$$b$$$ is equal to the sequence $$$a$$$, so this way to perform operations is one of the correct answers.
In the second test case, $$$n = 1$$$ and the only achiveable sequence $$$b$$$ is $$$[\, 0 \, ]$$$.
In the third test case, there are six possible sequences of operations:
None of them makes $$$b$$$ equal to $$$[\, 0, 1, 1 \,]$$$, so the answer is "NO".
Name |
---|