A15123 | Hard Cut
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 \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$ .
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$ .
输出格式
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.
- 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.
输入输出样例
输入 #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:
- $011_2 = 3_{10}$ ,
- $0_2 = 0_{10}$ ,
- $1_2 = 1_{10}$ .
$3 + 0 + 1 = 4$ , $4$ 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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted