아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

K-Goodness String

면접 대비

메모리 제한1024 MB

요약
문자열 S와 목표 K가 주어질 때, 이미 서로 다른 대칭 쌍의 수를 세고, 서로 다른 쌍이 정확히 K개가 되도록 바꿔야 하는 문자의 최소 개수를 구한다.
난이도

보통10점 중 4점

유형
문자열, 그리디, 구현, 수학
정답자
아직 제출이 없습니다

문제

Charles defines the goodness score of a string as the number of indices i such that Si ≠ SN−i+1 where 1 ≤ i ≤ N/2 (1-indexed). For example, the string CABABC has a goodness score of 2 since S2 ≠ S5 and S3 ≠ S4.

Charles gave Ada a string S of length N, consisting of uppercase letters and asked her to convert it into a string with a goodness score of K. In one operation, Ada can change any character in the string to any uppercase letter. Could you help Ada find the minimum number of operations required to transform the given string into a string with goodness score equal to K?

입력

The first line of the input gives the number of test cases, T. T test cases follow.

The first line of each test case contains two integers N and K. The second line of each test case contains a string S of length N, consisting of uppercase letters.

출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the minimum number of operations required to transform the given string S into a string with goodness score equal to K.

제한

  • 1 ≤ T ≤ 100.
  • 0 ≤ K ≤ N/2.

힌트

In Sample Case #1, the given string already has a goodness score of 1. Therefore the minimum number of operations required is 0.

In Sample Case #2, one option is to change the character at index 1 to B in order to have a goodness score of 2. Therefore, the minimum number of operations required is 1.

예제1

  1. 예제 1

    입력
    2
    5 1
    ABCAA
    4 2
    ABAA
    
    예상 출력
    Case #1: 0
    Case #2: 1