Codeforces Round 792 (Div. 1 + Div. 2)
H
Hard Cut
Codeforces
3400
原题
← G→
翻译中…

You are given a binary string $s$. You have to cut it into any number of non-intersecting substrings, so that the sum of binary integers denoted by these substrings is a power of 2. Each element of $s$ should be in exactly one substring.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). Description of the test cases follows.

翻译中…

Each test case contains a binary string $s$ ($1 \le |s| \le 10^6$).

翻译中…

It is guaranteed that the sum of $|s|$ over all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each test case output the answer to the problem as follows:

翻译中…
  • If the answer does not exist, output $-1$.
  • If the answer exists, firstly output an integer $k$ — the number of substrings in the answer. After that output $k$ non-intersecting substrings, for $i$-th substring output two integers $l_i, r_i$ ($1 \le l_i, r_i \le |s|$) — the description of $i$-th substring.
翻译中…

If there are multiple valid solutions, you can output any of them.

翻译中…

Note

翻译中…

In the first test case it is impossible to cut the string into substrings, so that the sum is a power of 2.

翻译中…

In the second test case such cut is valid:

翻译中…
  • $011_2 = 3_{10}$,
  • $0_2 = 0_{10}$,
  • $1_2 = 1_{10}$.
翻译中…

$3 + 0 + 1 = 4$, $4$ is a power of 2.

翻译中…

样例

Input #1
4
00000
01101
0111011001011
000111100111110
Output #1
-1

3
1 3
4 4
5 5

8
1 2
3 3
4 4
5 6
7 7
8 10
11 12
13 13

5
1 5
6 7
8 11
12 14
15 15
InputCopy OutputCopy
题目信息
题号
1684H
时间限制
2 s
内存限制
256 MB
标签
构造
DFS 及类似
分治
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。