No.859 Line A, Line B, Line C
タグ : / 解いたユーザー数 158
作問者 :
nmnmnmnmnmnmnm
/ テスター :
matsu7874
Problem Statement
Line A has stations from A1 to Ax, line B has stations from B1 to By, and line C has stations from C1 to Cz.
Each line is structured as shown in the figure below.
The train fare for traveling one station between adjacent stations is exactly 1 yen.
There is no fixed direction between stations, and you can travel freely in any direction by train.
Given the starting station and the destination station, find the lowest fare required to travel by train.
Input
$x$ $y$ $z$ $S_0$ $t_0$ $S_1$ $t_1$
Input Format
$x$, $y$, $z$ are the numbers of stations on lines A, B, and C, respectively.$x$, $y$, $z$ are positive integers. $1 \le x,y,z \le 1000000000 = 10^9$.
$S_0$ is the line name of the starting station, and $t_0$ is the station number of the starting station.
$S_1$ is the line name of the destination station, and $t_1$ is the station number of the destination station.
$S_i$ is one of the letters 'A', 'B', 'C'.
$t_i$ is a positive integer.
If $S_i$ is 'A', then $1 \le t_i \le x$.
If $S_i$ is 'B', then $1 \le t_i \le y$.
If $S_i$ is 'C', then $1 \le t_i \le z$.
The starting station and the destination station are never the same.
Output
Output the required fare on one line. Print a newline at the end.
Sample
Sample 1
Input
3 4 5 A 1 B 1
Output
1
There is no station between station A1 and station B1, that is, they are adjacent, so the fare is 1 yen.
This is the lowest possible fare.
Sample 2
Input
3 4 5 C 5 C 2
Output
3The fare from station C5 to station C2 is for 3 stations, so it is 3 yen.
Sample 3
Input
5 1 5 A 1 C 5
Output
2By traveling as station A1 → station B1 → station C5, the fare is only 2 yen.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。