問題一覧 > 通常問題

No.859 Line A, Line B, Line C

レベル : / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 158
作問者 : nmnmnmnmnmnmnm / テスター : matsu7874
お気に入りにしたユーザー ProblemId : 3084 / 自分の提出
問題文最終更新日: 2019-07-06 14:39:54
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 219 (順位表) の他の問題:

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
3
The 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
2
By traveling as station A1 → station B1 → station C5, the fare is only 2 yen.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。