2192B.md (2114B)
1 Source: https://codeforces.com/problemset/problem/2192/B 2 3 B. Flipping Binary String 4 5 time limit per test 6 7 1.5 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 You are given a binary string $s$ of length $n$. You can perform the following operation on the string: 22 23 * Choose an index $i$, and flip the bit present at all other indices except for the index $i$. In other words, choose an integer $i$ ($1 \le i \le n$), and for all $j$ such that $1 \le j \le n$ and $j \ne i$, if $s_j = 0$, then set $s_j:=1$, otherwise set $s_j:=0$. 24 25 You can perform the operation any number of times, but each index can be chosen by at most one operation. 26 27 Your task is to make all bits present in the string $s$ equal $0$, or report that it is impossible to do so. You don't have to minimize the number of operations. 28 29 Input 30 31 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows. 32 33 The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$). 34 35 The second line of each test case contains the binary string $s$ of length $n$. 36 37 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. 38 39 Output 40 41 For each test case, output $-1$ if it is impossible to transform all bits to $0$. Otherwise, output two lines in the following format: 42 43 * In the first line, print the number of operations $x$ ($0 \leq x \leq n$). 44 * In the second line of each test case, print $x$ numbers – the indices you select in each operation in order. You should guarantee that each index is chosen at most once. 45 46 If there are multiple possible solutions, you may output any. 47 48 Example 49 50 Input 51 52 ``` 53 4 54 55 3 56 57 101 58 59 3 60 61 100 62 63 4 64 65 0000 66 67 4 68 69 1010 70 ``` 71 72 Output 73 74 ``` 75 1 76 77 2 78 79 -1 80 81 0 82 83 2 84 85 1 3 86 ``` 87 88 Note 89 90 In the first test case, performing the operation on index $2$ means flipping bits present at index $1$ and $3$. So the new string formed will be $000$. 91 92 In the second test case, it can be shown that we cannot make string $a$ equal to $000$ using the described operations.