#601
Silver III
Feeding the Cows
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John has NN (1N1051 \le {N} \le {10^5}) cows, the breed of each being either a Guernsey or a Holstein. They have lined up horizontally with the cows occupying positions labeled from 1N1\dots N.

Since all the cows are hungry, FJ decides to plant grassy patches on some of the positions 1N1\dots N. Guernseys and Holsteins prefer different types of grass, so if Farmer John decides to plant grass at some location, he must choose to planting either Guernsey-preferred grass or Holstein-preferred grass --- he cannot plant both at the same location. Each patch of grass planted can feed an unlimited number of cows of the appropriate breed.

Each cow is willing to move a maximum of KK (0KN10 \le {K} \le N-1) positions to reach a patch. Find the minimum number of patches needed to feed all the cows. Also, print a configuration of patches that uses the minimum amount of patches needed to feed the cows. Any configuration that satisfies the above conditions will be considered correct.

입력

Each input contains TT test cases, each describing an arrangement of cows. The first line of input contains TT (1T101 \le T \le 10). Each of the TT test cases follow.

Each test case starts with a line containing NN and KK. The next line will contain a string of length NN, where each character denotes the breed of the iith cow (G meaning Guernsey and H meaning Holstein).

출력

For each of the TT test cases, please write two lines of output. For the first line, print the minimum number of patches needed to feed the cows. For the second line, print a string of length NN that describes a configuration that feeds all the cows with the minimum number of patches. The iith character, describing the iith position, should be a '.' if there is no patch, a 'G' if there is a patch that feeds Guernseys, and a 'H' if it feeds Holsteins. Any valid configuration will be accepted.

예제 입력 1

6
5 0
GHHGG
5 1
GHHGG
5 2
GHHGG
5 3
GHHGG
5 4
GHHGG
2 1
GH

예제 출력 1

5
GHHGG
3
.GH.G
2
..GH.
2
...GH
2
...HG
2
HG

점수

Inputs 2 through 4 have N10N \le 10. Inputs 5 through 8 have N40N \le 40. Inputs 9 through 12 have N105N \le 10^5.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Silver III1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.