CF1227C.Messy

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are fed up with your messy room, so you decided to clean it up.

Your room is a bracket sequence s=s1s2sns=s_{1}s_{2}\dots s_{n} of length nn . Each character of this string is either an opening bracket '(' or a closing bracket ')'.

In one operation you can choose any consecutive substring of ss and reverse it. In other words, you can choose any substring s[lr]=sl,sl+1,,srs[l \dots r]=s_l, s_{l+1}, \dots, s_r and change the order of elements in it into sr,sr1,,sls_r, s_{r-1}, \dots, s_{l} .

For example, if you will decide to reverse substring s[24]s[2 \dots 4] of string s=s= "((()))" it will be equal to s=s= "()(())".

A regular (aka balanced) bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.

A prefix of a string ss is a substring that starts at position 11 . For example, for s=s= "(())()" there are 66 prefixes: "(", "((", "(()", "(())", "(())(" and "(())()".

In your opinion, a neat and clean room ss is a bracket sequence that:

  • the whole string ss is a regular bracket sequence;
  • and there are exactly kk prefixes of this sequence which are regular (including whole ss itself).

For example, if k=2k = 2 , then "(())()" is a neat and clean room.

You want to use at most nn operations to make your room neat and clean. Operations are applied one after another sequentially.

It is guaranteed that the answer exists. Note that you do not need to minimize the number of operations: find any way to achieve the desired configuration in nn or less operations.

输入格式

The first line contains integer number tt ( 1t1001 \le t \le 100 ) — the number of test cases in the input. Then tt test cases follow.

The first line of a test case contains two integers nn and kk ( 1kn2,2n20001 \le k \le \frac{n}{2}, 2 \le n \le 2000 , nn is even) — length of ss and required number of regular prefixes.

The second line of a test case contains ss of length nn — the given bracket sequence. It contains only '(' and ')'.

It is guaranteed that there are exactly n2\frac{n}{2} characters '(' and exactly n2\frac{n}{2} characters ')' in the given string.

The sum of all values nn over all the test cases in the input doesn't exceed 20002000 .

输出格式

For each test case print an answer.

In the first line print integer mm ( 0mn0 \le m \le n ) — the number of operations. You do not need to minimize mm , any value is suitable.

In the following mm lines print description of the operations, each line should contain two integers l,rl,r ( 1lrn1 \le l \le r \le n ), representing single reverse operation of s[lr]=slsl+1srs[l \dots r]=s_{l}s_{l+1}\dots s_{r} . Operations are applied one after another sequentially.

The final ss after all operations should be a regular, also it should be exactly kk prefixes (including ss ) which are regular.

It is guaranteed that the answer exists. If there are several possible answers you can print any.

输入输出样例

  • 输入#1

    4
    8 2
    ()(())()
    10 3
    ))()()()((
    2 1
    ()
    2 1
    )(
    

    输出#1

    4
    3 4
    1 1
    5 8
    2 2
    3
    4 10
    1 4
    6 7
    0
    1
    1 2
    

说明/提示

In the first example, the final sequence is "()(()())", where two prefixes are regular, "()" and "()(()())". Note, that all the operations except "5 8" in the example output are useless (they do not change ss ).

首页