QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 2048 MB Points totaux : 100

#1361. 蚂蚁打字

Statistiques

考虑一个按键可以移动的配置式键盘。一只蚂蚁正在这个键盘的顶行上行走,需要输入一个数字字符串。蚂蚁从顶行的最左侧按键开始,该行包含 9 个按键,是数字 1 到 9 的某种排列。在每一秒钟,蚂蚁可以执行以下三种操作之一:

  1. 停留在当前按键上。输入该按键对应的数字。
  2. 向左移动一个按键。仅当蚂蚁不在最左侧按键时才能执行。
  3. 向右移动一个按键。仅当蚂蚁不在最右侧按键时才能执行。

计算在所有可能的数字按键排列中,蚂蚁输入给定数字字符串所需的最少秒数。

输入格式

输入包含一行,为一个字符串 $s$ ($1 \le |s| \le 10^5$),仅由 1 到 9 的数字字符组成。这是蚂蚁需要输入的数字字符串。

输出格式

输出一个整数,表示在所有可能的数字按键排列中,蚂蚁输入给定数字字符串所需的最少秒数。

样例

样例输入 1

78432579

样例输出 1

20

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.