CF1684H.Hard Cut
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤105 ). Description of the test cases follows.
Each test case contains a binary string s ( 1≤∣s∣≤106 ).
It is guaranteed that the sum of ∣s∣ over all test cases does not exceed 106 .
输出格式
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 li,ri ( 1≤li,ri≤∣s∣ ) — the description of i -th substring.
If there are multiple valid solutions, you can output any of them.
输入输出样例
输入#1
4 00000 01101 0111011001011 000111100111110
输出#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
说明/提示
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:
- 0112=310 ,
- 02=010 ,
- 12=110 .
3+0+1=4 , 4 is a power of 2.