CF1852D.Miriany and Matchstick
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Miriany's matchstick is a 2×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 † is equal to k . If it is impossible, report so.
† An adjacent pair of cells with different characters is a pair of cells (r1,c1) and (r2,c2) ( 1≤r1,r2≤2 , 1≤c1,c2≤n ) such that ∣r1−r2∣+∣c1−c2∣=1 and the characters in (r1,c1) and (r2,c2) are different.
输入格式
The first line consists of an integer t , the number of test cases ( 1≤t≤1000 ). The description of the test cases follows.
The first line of each test case has two integers, n and k ( 1≤n≤2⋅105,0≤k≤3⋅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 s of n characters ( si is either A or B) – Miriany's top row of the matchstick.
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 way to fill the second row with the number of adjacent pairs of cells with different characters equals k , output "NO".
Otherwise, output "YES". Then, print n 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 2 of the grid such that k=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.
ABAAABAB The pairs of different characters are shown below in red:
ABAAABAB —————————————————
ABAAABAB
—————————————————
ABAAABAB
—————————————————
ABAAABAB
—————————————————
ABAAABAB
There are a total of 5 pairs, which satisfies k .