시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB127763.636%

문제

Jieun wants to play a musical score of length $N$ using $K$($K \le N$) music boxes. The score is a string of length $N$ consisting of digits from 0 to 9. She plans to divide the score into $K$ non-empty consecutive segments and assign each segment to one music box, and each music box is assigned to exactly one segment.

Each music box can only play a digit pattern that is stored in it, repeated infinitely. For example, if a music box stores "123", then it will play the sequence "123123123...". For each segment, the assigned part of the score must exactly match a prefix of the infinitely repeated sequence played by that music box. For instance, suppose a music box is assigned the segment "12121". Patterns such as "12", "1212", or "12121" can be stored in the box to reproduce this segment, because repeating them produces a sequence whose prefix matches "12121". However, storing "121" or "1" would result in "121121..." or "11111...", respectively, which do not match the given segment.

Jieun wants to divide the score into $K$ segments and assign an appropriate pattern to each music box so that the entire score is played correctly. However, if a music box must store a pattern that is too long, it may break. Therefore, she wants to minimize the maximum length of the patterns stored in the music boxes. Your task is to determine the minimum possible value of the maximum pattern length, over all valid ways to divide the score into $K$ segments and assign patterns to the music boxes.

입력

The first line contains two integers $N$ and $K$, where $N$ is the musical score length and $K$ is the number of music boxes. ($1 \le N \le 100\,000, 1 \le K \le N$)

The second line contains a string of length $N$ consisting of digits from 0 to 9, representing the musical score.

출력

Print a single integer: the minimum possible value of the maximum pattern length stored in any music box when the score is divided into $K$ segments and each segment is assigned an appropriate repeating pattern.

서브태스크

번호배점제한
120

$1 \le N \le 100, K = 1$

210

$1 \le N \le 100, K = 2$

310

$1 \le N \le 100, 1 \le K \le N$

410

$1 \le N \le 2\,000, K = 1$

510

$1 \le N \le 2\,000, K = 2$

610

$1 \le N \le 2\,000, 1 \le K \le N$

710

$1 \le N \le 100\,000, K = 1$

810

$1 \le N \le 100\,000, K = 2$

910

$1 \le N \le 100\,000, 1 \le K \le N$

예제 입력 1

5 1
12121

예제 출력 1

2

The music box can store patterns like "12", "1212", or "12121". In this case, the shortest pattern is "12".

This example satisfies the conditions of Subtask 1, 3, 4, 6, 7 and 9.

예제 입력 2

10 2
1231232132

예제 출력 2

3

In this example, the optimal way to split the sheet music is into "12312" and "32132", and in that case, it is optimal to store "123" and "321" in each music box, respectively.

Another optimal way is to split it into "123123" and "2132", and then store "123" and "213" in each music box, respectively.

This example satisfies the conditions of Subtask 2, 3, 5, 6, 8 and 9.

예제 입력 3

20 3
12121200700700121212

예제 출력 3

3

In this example, the optimal way to split the sheet music is into "121212", "00700700" and "121212", and in that case, it is optimal to store "12", "007" and "12" in each music box, respectively.

This example satisfies the conditions of Subtask 3, 6 and 9.

노트

The length of a pattern is defined as the number of digits it contains. For example, "12" has length $2$, and "1171" has length $4$.

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.