103731: [Atcoder]ABC373 B - 1D Keyboard
Description
Score : $200$ points
Problem Statement
There is a keyboard with $26$ keys arranged on a number line.
The arrangement of this keyboard is represented by a string $S$, which is a permutation of ABCDEFGHIJKLMNOPQRSTUVWXYZ
.
The key corresponding to the character $S_x$ is located at coordinate $x$ $(1 \leq x \leq 26)$. Here, $S_x$ denotes the $x$-th character of $S$.
You will use this keyboard to input ABCDEFGHIJKLMNOPQRSTUVWXYZ
in this order, typing each letter exactly once with your right index finger.
To input a character, you need to move your finger to the coordinate of the key corresponding to that character and press the key.
Initially, your finger is at the coordinate of the key corresponding to A
. Find the minimal possible total traveled distance of your finger from pressing the key for A
to pressing the key for Z
. Here, pressing a key does not contribute to the distance.
Constraints
- $S$ is a permutation of
ABCDEFGHIJKLMNOPQRSTUVWXYZ
.
Input
The input is given from Standard Input in the following format:
$S$
Output
Print the answer.
Sample Input 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Sample Output 1
25
From pressing the key for A
to pressing the key for Z
, you need to move your finger $1$ unit at a time in the positive direction, resulting in a total traveled distance of $25$. It is impossible to press all keys with a total traveled distance less than $25$, so print 25
.
Sample Input 2
MGJYIZDKSBHPVENFLQURTCWOAX
Sample Output 2
223
Output
问题陈述
有一个带有26个键的键盘排列在数轴上。
这个键盘的排列由一个字符串S表示,S是ABCDEFGHIJKLMNOPQRSTUVWXYZ
的一个排列。
对应于字符$S_x$的键位于坐标$x$($1 \leq x \leq 26$)。这里,$S_x$表示S的第$x$个字符。
你将使用这个键盘输入ABCDEFGHIJKLMNOPQRSTUVWXYZ
,按照这个顺序,用你的右食指精确地输入每个字母一次。
要输入一个字符,你需要将手指移动到对应于该字符的键的坐标上,并按下该键。
最初,你的手指位于对应于A
的键的坐标上。找出从按下A键到按下Z键,你手指可能的最小总移动距离。这里,按下键不计算在距离内。
约束条件
- $S$是
ABCDEFGHIJKLMNOPQRSTUVWXYZ
的一个排列。
输入
输入从标准输入以下格式给出:
$S$
输出
打印答案。
样本输入1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
样本输出1
25
从按下A键到按下Z键,你需要每次将手指向正方向移动1个单位,总移动距离为25。不可能以小于25的总移动距离按下所有键,所以打印25
。
样本输入2
MGJYIZDKSBHPVENFLQURTCWOAX
样本输出2
223