CF1684H.Hard Cut

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a binary string ss. 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 ss should be in exactly one substring.

给你一个二进制字符串 ss。你需要将它分割成任意数量的互不相交的子串,使得这些子串所表示的二进制整数之和为 2 的幂。字符串 ss 中的每个字符必须且仅属于其中一个子串。

输入格式

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

Each test case contains a binary string ss (1≤∣s∣≤1061 \le |s| \le 10^6).

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1051 \le t \le 10^5)。随后是测试用例的描述。

每个测试用例包含一个二进制字符串 ss(1≤∣s∣≤1061 \le |s| \le 10^6)。

保证所有测试用例的 ∣s∣|s| 之和不超过 10610^6。

输出格式

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

  • If the answer does not exist, output −1-1.
  • If the answer exists, firstly output an integer kk — the number of substrings in the answer. After that output kk non-intersecting substrings, for ii-th substring output two integers li,ril_i, r_i (1≤li,ri≤∣s∣1 \le l_i, r_i \le |s|) — the description of ii-th substring.

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

对每个测试用例,按如下格式输出问题的答案:

  • 如果答案不存在,输出 −1-1。
  • 如果答案存在,首先输出一个整数 kk —— 答案中子串的个数;然后输出 kk 个互不相交的子串;对第 ii 个子串,输出两个整数 li,ril_i, r_i(1≤li,ri≤∣s∣1 \le l_i, r_i \le |s|)—— 描述第 ii 个子串。

若存在多个合法解,可输出其中任意一个。

输入输出样例

  • 输入#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=310011_2 = 3_{10},
  • 02=0100_2 = 0_{10},
  • 12=1101_2 = 1_{10}.

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

在第一个测试用例中,无法将字符串分割成若干子串,使得这些子串的和为 2 的幂。

在第二个测试用例中,如下分割是合法的:

  • 0112=310011_2 = 3_{10},
  • 02=0100_2 = 0_{10},
  • 12=1101_2 = 1_{10}.

3+0+1=43 + 0 + 1 = 4,而 44 是 2 的幂。

输入解题思路,AI测评打分。不知道怎么写?

首页