Logo
(追記) (追記ここまで)

8338번 - Type Two de Bruijn Sequences 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB38151443.750%

문제

A word s composed of (2n + n - 1) characters 0 and 1 is called a de Bruijn sequence of order n if every n-character word composed of zeroes and ones is its subword - that is a fragment of consecutive characters - of s. An example of a de Bruijn sequence of order 3 is 0001011100.

A type two de Bruijn sequence of order n is such a word s of arbitrary length that each n-character word composed of zeroes and ones is a subsequence - that is a fragment of not necessarily consecutive characters - of s. An example of a type two de Bruijn sequence of order 3 is 00101101. As far as we know, Nicolaas Govert de Bruijn did not invent such sequences, but their definition is similar to the previous one, isn't it?

Let us consider a word s composed only of zeroes and ones. How many digits (0 or 1, of course) have to be added at the end of s for the word to become a type two de Bruijn sequence of order n?

입력

The first line of the standard input contains two integers m and n (1 ≤ m, n ≤ 1,000,000), separated by a single space. The second line contains an m-character word s composed only of digits 0 and 1 that does not contain any spaces.

출력

The first and only line of the standard output should contain a single non-negative integer, denoting the minimal number of digits that need to be added at the end of the word s for it to become a t.t.d.B.s. of order n.

제한

예제 입력 1

5 3
00101

예제 출력 1

2

힌트

After adding the characters 01 we obtain the following t.t.d.B.s. of order 3: 0010101.

출처

Contest > Algorithmic Engagements > PA 2009 7-1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /