CF1884B.Haunted House
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a number in binary representation consisting of exactly n bits, possibly, with leading zeroes. For example, for n=5 the number 6 will be given as 00110 , and for n=4 the number 9 will be given as 1001 .
Let's fix some integer i such that 1≤i≤n . In one operation you can swap any two adjacent bits in the binary representation. Your goal is to find the smallest number of operations you are required to perform to make the number divisible by 2i , or say that it is impossible.
Please note that for each 1≤i≤n you are solving the problem independently.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤104 ). The description of the test cases follows.
The first line of each test case contains one integer n ( 1≤n≤105 ) — the length of the binary representation of the number.
The second line of each test case contains a string of length n , consisting of 0 and 1 , — the binary representation of the number.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, for each 1≤i≤n output the smallest number of operations required to make the number divisible by 2i , or output −1 if it is impossible.
输入输出样例
输入#1
6 1 1 2 01 3 010 5 10101 7 0000111 12 001011000110
输出#1
-1 1 -1 0 1 -1 1 3 -1 -1 -1 3 6 9 12 -1 -1 -1 0 2 4 6 10 15 20 -1 -1 -1 -1 -1
说明/提示
In the first test case, we cannot swap any elements, and the number 1 is not divisible by 2 .
In the second test case, the initial number is 1 . It is not divisible by 2 , but if we perform the operation, then we obtain the number with binary representation 10 , which is equal to 2 in decimal representation, thus, it is divisible by 2 . But this number is not divisible by 4 and we cannot obtain any other number using the operations.
In the third test case, the initial number is 2 . For i=1 we do not have to perform any operations since the initial number is divisible by 2 . For i=2 we can perform one operation swapping the first two bits (we would obtain 100 in binary representation, which corresponds to number 4 ). There is no answer for i=3 .