CF1852D.Miriany and Matchstick
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
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.
米里安妮的火柴棒是一个 2×n 的网格,需要用字符 A 或 B 填满。
她已经填好了网格的第一行,现在请你填写第二行。你的填写方式必须使得字符不同的相邻格子对的数量恰好等于 k;若无法做到,请报告不可能。
† 字符不同的相邻格子对是指一对格子 (r1,c1) 和 (r2,c2)(其中 1≤r1,r2≤2,1≤c1,c2≤n),满足 ∣r1−r2∣+∣c1−c2∣=1,且格子 (r1,c1) 与 (r2,c2) 中的字符不同。
输入格式
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.
第一行包含一个整数 t,表示测试用例的数量(1≤t≤1000)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤2⋅105,0≤k≤3⋅n)——分别表示火柴棒的列数,以及要求的相邻单元格中字符不同的对数。
下一行包含一个长度为 n 的字符串 s(每个字符 si 为 A 或 B)——即 Miriany 的火柴棒顶行。
保证所有测试用例的 n 之和不超过 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.
对于每个测试用例,若无法在第二行填入字符,使得相邻且字符不同的单元格对的数量恰好等于 k,则输出 "NO"。
否则,输出 "YES";然后输出 n 个字符,表示 Miriany 的火柴棒图案中一个合法的底行。若存在多个合法答案,输出任意一个即可。
输入输出样例
输入#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.
在第一个测试用例中,可以证明:不存在任何方式来填写网格的第 2 行,使得 k=1。
在第二个测试用例中,BABB 是一个可能的答案。
下图是将 BABB 填入第二行后得到的网格:
ABAAABAB
以下用红色标出了所有字符不同的配对:
ABAAABAB
—————————————————
ABAAABAB
—————————————————
ABAAABAB
—————————————————
ABAAABAB
—————————————————
ABAAABAB
共有 5 对,满足 k 的要求。
输入解题思路,AI测评打分。不知道怎么写?