QOJ.ac

QOJ

Límite de tiempo: 0.5 s Límite de memoria: 256 MB Puntuación total: 100

#13164. 二进制字符串

Estadísticas

二进制字符串是由 0 和 1 组成的非空序列,例如 010110, 1, 11101 等。Ayu 有一个她最喜欢的二进制字符串 $S$,且该字符串不包含前导零。她想用计算器将 $S$ 转换为其十进制表示。

不幸的是,她的计算器无法处理任何大于 $K$ 的整数,否则会崩溃。因此,Ayu 可能需要从 $S$ 中删除零个或多个位,同时保持剩余位的顺序,使得其十进制表示不超过 $K$。生成的二进制字符串也必须不包含前导零。

你的任务是帮助 Ayu 确定为了满足她的需求,最少需要从 $S$ 中删除多少位。

例如,设 $S = 1100101$ 且 $K = 13$。注意 $1100101$ 的十进制表示为 $101$,因此我们需要从 $S$ 中删除若干位,使其不超过 $K$。我们可以删除第 $3$ 位、$5$ 位和 $6$ 位(从最高有效位开始计数),即 $1100101 \to 1101$。$1101$ 的十进制表示为 $13$,不超过 $K = 13$。在这个例子中,我们删除了 $3$ 位,这是可能的最小值(如果我们只删除 $2$ 位,那么我们将得到一个长度为 $5$ 位的二进制字符串;请注意,任何长度为 $5$ 位的二进制字符串的十进制值至少为 $16$)。

输入格式

输入的第一行包含一个整数 $K$ ($1 \le K \le 2^{60}$),代表 Ayu 计算器的限制。 第二行包含一个二进制字符串 $S$ ($1 \le |S| \le 60$),代表 Ayu 最喜欢的二进制字符串。你可以安全地假设 $S$ 不包含前导零。

输出格式

输出一行,包含一个整数,表示需要从 $S$ 中删除的最少位数。

样例

输入 1

13
1100101

输出 1

3

说明 1

此样例由上述题目描述中的例子说明。

输入 2

13
1111111

输出 2

4

说明 2

Ayu 必须删除 $4$ 位才能得到 $111$,其十进制表示为 $7$。

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.