CF1658F.Juju and Binary String

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The cuteness of a binary string is the number of 1\texttt{1}s divided by the length of the string. For example, the cuteness of 01101\texttt{01101} is 35\frac{3}{5}.

Juju has a binary string ss of length nn. She wants to choose some non-intersecting subsegments of ss such that their concatenation has length mm and it has the same cuteness as the string ss.

More specifically, she wants to find two arrays ll and rr of equal length kk such that 1≤l1≤r1<l2≤r2<…<lk≤rk≤n1 \leq l_1 \leq r_1 \lt l_2 \leq r_2 \lt \ldots \lt l_k \leq r_k \leq n, and also:

  • ∑i=1k(ri−li+1)=m\sum\limits_{i=1}^k (r_i - l_i + 1) = m;
  • The cuteness of s[l1,r1]+s[l2,r2]+…+s[lk,rk]s[l_1,r_1]+s[l_2,r_2]+\ldots+s[l_k,r_k] is equal to the cuteness of ss, where s[x,y]s[x, y] denotes the subsegment sxsx+1…sys_x s_{x+1} \ldots s_y, and ++ denotes string concatenation.

Juju does not like splitting the string into many parts, so she also wants to minimize the value of kk. Find the minimum value of kk such that there exist ll and rr that satisfy the constraints above or determine that it is impossible to find such ll and rr for any kk.

一个二进制字符串的“可爱度”(cuteness)定义为其中字符 1\texttt{1} 的个数除以字符串长度。例如,01101\texttt{01101} 的可爱度为 35\frac{3}{5}。

Juju 有一个长度为 nn 的二进制字符串 ss。她希望从中选出若干个互不相交的子段,使得这些子段拼接后总长度恰好为 mm,且拼接所得字符串的可爱度与原字符串 ss 相同。

更准确地说,她希望找到两个长度均为 kk 的数组 ll 和 rr,满足

1≤l1≤r1<l2≤r2<…<lk≤rk≤n,1 \leq l_1 \leq r_1 < l_2 \leq r_2 < \ldots < l_k \leq r_k \leq n,

且满足以下条件:

  • ∑i=1k(ri−li+1)=m\sum\limits_{i=1}^k (r_i - l_i + 1) = m;
  • 字符串 s[l1,r1]+s[l2,r2]+…+s[lk,rk]s[l_1,r_1]+s[l_2,r_2]+\ldots+s[l_k,r_k] 的可爱度等于 ss 的可爱度,其中 s[x,y]s[x, y] 表示子段 sxsx+1…sys_x s_{x+1} \ldots s_y,而 ++ 表示字符串拼接。

Juju 不喜欢将字符串分割成太多段,因此她还希望最小化 kk 的值。请找出满足上述约束的最小 kk 值;若对任意 kk 均不存在满足条件的 ll 和 rr,则判定为不可能。

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains two integers nn and mm (1≤m≤n≤2⋅1051 \leq m \leq n \leq 2 \cdot 10^5).

The second line of each test case contains a binary string ss of length nn.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤m≤n≤2⋅1051 \leq m \leq n \leq 2 \cdot 10^5)。

每个测试用例的第二行包含一个长度为 nn 的二进制字符串 ss。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, if there is no valid pair of ll and rr, print −1-1.

Otherwise, print k+1k + 1 lines.

In the first line, print a number kk (1≤k≤m1 \leq k \leq m) — the minimum number of subsegments required.

Then print kk lines, the ii-th should contain lil_i and rir_i (1≤li≤ri≤n1 \leq l_i \leq r_i \leq n) — the range of the ii-th subsegment. Note that you should output the subsegments such that the inequality l1≤r1<l2≤r2<…<lk≤rkl_1 \leq r_1 \lt l_2 \leq r_2 \lt \ldots \lt l_k \leq r_k is true.

对于每个测试用例,若不存在满足条件的 ll 和 rr 对,则输出 −1-1。

否则,输出 k+1k + 1 行。

第一行输出一个整数 kk(1≤k≤m1 \leq k \leq m),表示所需的最小子段数量。

随后输出 kk 行,第 ii 行应包含 lil_i 和 rir_i(1≤li≤ri≤n1 \leq l_i \leq r_i \leq n),表示第 ii 个子段的范围。注意:所输出的子段必须满足不等式 l1≤r1<l2≤r2<…<lk≤rkl_1 \leq r_1 \lt l_2 \leq r_2 \lt \ldots \lt l_k \leq r_k。

输入输出样例

  • 输入#1

    4
    4 2
    0011
    8 6
    11000011
    4 3
    0101
    5 5
    11111

    输出#1

    1
    2 3
    2
    2 3
    5 8
    -1
    1
    1 5

说明/提示

In the first example, the cuteness of 0011\texttt{0011} is the same as the cuteness of 01\texttt{01}.

In the second example, the cuteness of 11000011\texttt{11000011} is 12\frac{1}{2} and there is no subsegment of size 66 with the same cuteness. So we must use 22 disjoint subsegments 10\texttt{10} and 0011\texttt{0011}.

In the third example, there are 88 ways to split the string such that ∑i=1k(ri−li+1)=3\sum\limits_{i=1}^k (r_i - l_i + 1) = 3 but none of them has the same cuteness as 0101\texttt{0101}.

In the last example, we don't have to split the string.

在第一个例子中,字符串 0011\texttt{0011} 的“可爱度”与字符串 01\texttt{01} 的“可爱度”相同。

在第二个例子中,字符串 11000011\texttt{11000011} 的“可爱度”为 12\frac{1}{2},且不存在长度为 66 的子段具有相同的“可爱度”。因此我们必须使用两个互不相交的子段 10\texttt{10} 和 0011\texttt{0011}。

在第三个例子中,共有 88 种将字符串划分的方式使得 ∑i=1k(ri−li+1)=3\sum\limits_{i=1}^k (r_i - l_i + 1) = 3,但其中没有任何一种划分方式所得各子段的“可爱度”均与 0101\texttt{0101} 的“可爱度”相同。

在最后一个例子中,我们无需对字符串进行划分。

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

首页