CF1658F.Juju and Binary String
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The cuteness of a binary string is the number of 1 s divided by the length of the string. For example, the cuteness of 01101 is 53 .
Juju has a binary string s of length n . She wants to choose some non-intersecting subsegments of s such that their concatenation has length m and it has the same cuteness as the string s .
More specifically, she wants to find two arrays l and r of equal length k such that 1≤l1≤r1<l2≤r2<…<lk≤rk≤n , and also:
- i=1∑k(ri−li+1)=m ;
- The cuteness of s[l1,r1]+s[l2,r2]+…+s[lk,rk] is equal to the cuteness of s , where s[x,y] denotes the subsegment sxsx+1…sy , and + denotes string concatenation.
Juju does not like splitting the string into many parts, so she also wants to minimize the value of k . Find the minimum value of k such that there exist l and r that satisfy the constraints above or determine that it is impossible to find such l and r for any k .
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases.
The first line of each test case contains two integers n and m ( 1≤m≤n≤2⋅105 ).
The second line of each test case contains a binary string s of length n .
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, if there is no valid pair of l and r , print −1 .
Otherwise, print k+1 lines.
In the first line, print a number k ( 1≤k≤m ) — the minimum number of subsegments required.
Then print k lines, the i -th should contain li and ri ( 1≤li≤ri≤n ) — the range of the i -th subsegment. Note that you should output the subsegments such that the inequality l1≤r1<l2≤r2<…<lk≤rk 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 is the same as the cuteness of 01 .
In the second example, the cuteness of 11000011 is 21 and there is no subsegment of size 6 with the same cuteness. So we must use 2 disjoint subsegments 10 and 0011 .
In the third example, there are 8 ways to split the string such that i=1∑k(ri−li+1)=3 but none of them has the same cuteness as 0101 .
In the last example, we don't have to split the string.