CF1852D.Miriany and Matchstick

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Miriany's matchstick is a 2×n2 \times n grid that needs to be filled with characters A or B.

He has already filled in the first row of the grid and would like you to fill in the second row. You must do so in a way such that the number of adjacent pairs of cells with different characters ^\dagger is equal to kk . If it is impossible, report so.

^\dagger An adjacent pair of cells with different characters is a pair of cells (r1,c1)(r_1, c_1) and (r2,c2)(r_2, c_2) ( 1r1,r221 \le r_1, r_2 \le 2 , 1c1,c2n1 \le c_1, c_2 \le n ) such that r1r2+c1c2=1|r_1 - r_2| + |c_1 - c_2| = 1 and the characters in (r1,c1)(r_1, c_1) and (r2,c2)(r_2, c_2) are different.

输入格式

The first line consists of an integer tt , the number of test cases ( 1t10001 \leq t \leq 1000 ). The description of the test cases follows.

The first line of each test case has two integers, nn and kk ( 1n2105,0k3n1 \leq n \leq 2 \cdot 10^5, 0 \leq k \leq 3 \cdot n ) – the number of columns of the matchstick, and the number of adjacent pairs of cells with different characters required.

The following line contains string ss of nn characters ( sis_i is either A or B) – Miriany's top row of the matchstick.

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 way to fill the second row with the number of adjacent pairs of cells with different characters equals kk , output "NO".

Otherwise, output "YES". Then, print nn characters that a valid bottom row for Miriany's matchstick consists of. If there are several answers, output any of them.

输入输出样例

  • 输入#1

    4
    10 1
    ABBAAABBAA
    4 5
    AAAA
    9 17
    BAAABBAAB
    4 9
    ABAB

    输出#1

    NO
    YES
    BABB
    YES
    ABABAABAB
    NO

说明/提示

In the first test case, it can be proved that there exists no possible way to fill in row 22 of the grid such that k=1k = 1 .

For the second test case, BABB is one possible answer.

The grid below is the result of filling in BABB as the second row.

AAAABABB\begin{array}{|c|c|} \hline A & A & A & A \cr \hline B & A & B & B \cr \hline \end{array} The pairs of different characters are shown below in red:

AAAABABB\begin{array}{|c|c|} \hline \color{red}{A} & A & A & A \cr \hline \color{red}{B} & A & B & B \cr \hline \end{array} —————————————————

AAAABABB\begin{array}{|c|c|} \hline A & A & \color{red}{A} & A \cr \hline B & A & \color{red}{B} & B \cr \hline \end{array}

—————————————————

AAAABABB\begin{array}{|c|c|} \hline A & A & A & \color{red}{A} \cr \hline B & A & B & \color{red}{B} \cr \hline \end{array}

—————————————————

AAAABABB\begin{array}{|c|c|} \hline A & A & A & A \cr \hline \color{red}{B} & \color{red}{A} & B & B \cr \hline \end{array}

—————————————————

AAAABABB\begin{array}{|c|c|} \hline A & A & A & A \cr \hline B & \color{red}{A} & \color{red}{B} & B \cr \hline \end{array}

There are a total of 55 pairs, which satisfies kk .

首页