QOJ.ac

QOJ

时间限制: 2 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#13501. 比特是危险的

统计

你觉得从梦境中逃脱很容易吗?当这个梦境与比特(bit)有关时,情况就并非如此了。你昨天肯定读了太多关于比特理论的东西,但这现在都不重要了,因为你唯一想做的就是从梦中醒来。你可能找错了那个最佳的特殊字符串……或者他们只是在骗你。在闭上的双眼面前,你仍然能看到一长串比特。

接着你意识到,你有能力将这个字符串的最左侧比特从 0 变为 1,或者从 1 变为 0。这需要花费你整整 4 秒,但你确实可以做到!

然后你又意识到,你还可以将这个字符串循环移动,向左移动一位或向右移动一位。在这个奇怪的梦境中,这两种操作中的任何一种都需要花费你整整 7 秒。

直觉告诉你,字符串中的那些 1-比特正是将你困在梦境中的原因。既然这可能是真的,你决定将字符串变成全 0 字符串——你知道你拥有为此所需的一切条件。

但如果你以最优方式行动,需要花费多少时间?

输入格式

输入只有一行,包含一个字符串 $S$ ($2 \le |S| \le 2 \cdot 10^5$) —— 由 0 和 1 组成的字符串。

输出格式

输出将 $S$ 转换为全 0 字符串所需的最小时间,以秒为单位。

样例

输入样例 1

11001

输出样例 1

33

输入样例 2

01101010

输出样例 2

58

输入样例 3

1000110101

输出样例 3

62

输入样例 4

011010100011

输出样例 4

94

输入样例 5

0000

输出样例 5

0

说明

在第一个样例中,最优策略如下:

  • 修改最左侧比特得到 01001
  • 将字符串循环左移得到 10010
  • 修改最左侧比特得到 00010
  • 将字符串循环右移得到 00001
  • 再次将字符串循环右移得到 10000
  • 修改最左侧比特得到 00000

三次修改和三次循环移位总共需要恰好 33 秒。

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.