CF1898A.Milica and String

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Milica has a string ss of length nn , consisting only of characters A and B. She wants to modify ss so it contains exactly kk instances of B. In one operation, she can do the following:

  • Select an integer ii ( 1in1 \leq i \leq n ) and a character cc ( cc is equal to either A or B).
  • Then, replace each of the first ii characters of string ss (that is, characters s1,s2,,sis_1, s_2, \ldots, s_i ) with cc .

Milica does not want to perform too many operations in order not to waste too much time on them.

She asks you to find the minimum number of operations required to modify ss so it contains exactly kk instances of B. She also wants you to find these operations (that is, integer ii and character cc selected in each operation).

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t5001 \leq t \leq 500 ). The description of test cases follows.

The first line of each test case contains two integers nn and kk ( 3n1003 \leq n \leq 100 , 0kn0 \leq k \leq n ) — the length of the string ss and the number of characters B Milica wants to appear in ss in the end.

The second line of each test case contains the string ss of length nn , consisting only of characters A and B.

输出格式

For each test case, in the first line output a single integer mm — the minimum number of operations Milica should perform.

In the jj -th of the next mm lines output an integer ii ( 1in1 \le i \le n ) and a character cc ( cc is 'A' or 'B') — the parameters of the jj -th operation as described in the statement.

If there are multiple solutions with the minimum possible number of operations, output any of them.

输入输出样例

  • 输入#1

    5
    5 2
    AAABB
    5 3
    AABAB
    5 0
    BBBBB
    3 0
    BAA
    10 3
    BBBABBBBAB

    输出#1

    0
    1
    1 B
    1
    5 A
    1
    2 A
    1
    6 A

说明/提示

In the first test case, there are already 22 characters B in ss , so Milica does not have to perform any operations.

In the second test case, the only way to achieve 33 characters B in ss in one operation is to replace the first character of ss by B on the first operation: AABAB \rightarrow BABAB.

In the third test case, the only way to achieve 00 characters B in ss in one operation is to replace the first 55 characters of ss by A on the first operation: BBBBB \rightarrow AAAAA.

In the fourth test case, one of the ways to achieve 00 characters B in ss in one operation is to replace the first 22 characters of ss by A on the first operation: BAA \rightarrow AAA. Note that "1 A" and "3 A" are also correct one-operation solutions.

首页