201400: [AtCoder]ARC140 A - Right String

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

For a string $T$ consisting of lowercase English letters, consider the question below, and let $f(T)$ be the answer.

Find the number of different strings obtained by performing the following operation any number of times: delete the first character from $T$ and append it to the end.

You are given a string $S$ of length $N$ consisting of lowercase English letters. You can perform the operation below at most $K$ times (possibly zero).

  • Choose a character of $S$ and change it to any lowercase English letter.

Find the minimum possible value of $f(S)$ after your operations.

Constraints

  • $1 \le N \le 2000$
  • $0 \le K \le N$
  • $S$ is a string of length $N$ consisting of lowercase English letters.
  • $N$ and $K$ are integers.

Input

Input is given from Standard Input in the following format:

$N$ $K$
$S$

Output

Print the answer.


Sample Input 1

4 1
abac

Sample Output 1

2

If you change the fourth character c to b in the first operation, you get $S=$ abab, with $f(S)=2$.

$f(S)$ cannot be made $1$ or less in one or fewer operations, so the answer is $2$.


Sample Input 2

10 0
aaaaaaaaaa

Sample Output 2

1

Sample Input 3

6 1
abcaba

Sample Output 3

3

Input

题意翻译

给定一种字符串值 $f(s)$ 的定义为: 不断将它首位字符插入到最后一位的后面,最后能获得的最大字符串种类个数。 得到该定义后,给定整数 $N$ 与 $K$。$N$ 代表给定只含小写字母的字符串长度,$K$ 代表可供修改的次数。 求 $K$ 次修改(只能修改为小写字母)后可以得到最小 $f(s)$。

加入题单

上一题 下一题 算法标签: