CF1658F.Juju and Binary String

普及/提高-

通过率:0%

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 1l1r1<l2r2<<lkrkn1 \leq l_1 \leq r_1 < l_2 \leq r_2 < \ldots < l_k \leq r_k \leq n , and also:

  • i=1k(rili+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+1sys_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 .

输入格式

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

The first line of each test case contains two integers nn and mm ( 1mn21051 \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 21052 \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 ( 1km1 \leq k \leq m ) — the minimum number of subsegments required.

Then print kk lines, the ii -th should contain lil_i and rir_i ( 1lirin1 \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 l1r1<l2r2<<lkrkl_1 \leq r_1 < l_2 \leq r_2 < \ldots < l_k \leq r_k is true.

输入输出样例

  • 输入#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(rili+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.

首页