QOJ.ac

QOJ

时间限制: 1 s 内存限制: 32 MB 总分: 100

#10989. 第二类 de Bruijn 序列

统计

由 $(2^{n} + n - 1)$ 个字符 01 组成的字符串 $s$ 如果满足每一个长度为 $n$ 的由 01 组成的字符串都是 $s$ 的子串(即 $s$ 中连续的片段),则称其为 $n$ 阶 de Bruijn 序列。例如,0001011100 是一个 3 阶 de Bruijn 序列。

$n$ 阶二型 de Bruijn 序列是指一个任意长度的字符串 $s$,使得每一个长度为 $n$ 的由 01 组成的字符串都是 $s$ 的子序列(即 $s$ 中不一定连续的片段)。例如,00101101 是一个 3 阶二型 de Bruijn 序列。据我们所知,Nicolaas Govert de Bruijn 并没有发明这种序列,但它们的定义与前者类似,不是吗?

考虑一个仅由 01 组成的字符串 $s$。为了使该字符串成为 $n$ 阶二型 de Bruijn 序列,需要在 $s$ 的末尾添加多少个数字(当然是 01)?

输入格式

第一行包含两个整数 $m$ 和 $n$ ($1 \le m, n \le 1\,000\,000$),由一个空格分隔。第二行包含一个长度为 $m$ 的字符串 $s$,仅由数字 01 组成,且不包含空格。

输出格式

第一行且仅有一行输出一个非负整数,表示为了使字符串 $s$ 成为 $n$ 阶二型 de Bruijn 序列,需要在其末尾添加的最少数字个数。

样例

输入 1

5 3
00101

输出 1

2

说明 1

在添加字符 01 后,我们得到了以下 3 阶二型 de Bruijn 序列:0010101

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.