Logo
(追記) (追記ここまで)

34309번 - Mines Motor Company 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB52434086.957%

문제

A group of highly successful Mines Computer Science and Mechanical Engineering graduates decided to create an electric car company called Mines Motor Company. The company has been very successful and recently opened their production plant. In the production plant, there are multiple workstations in a grid layout. The rows and columns of the grid are both labeled using uppercase letters (A-Z for rows from top to bottom, and A-Z for columns from left to right). Figure 1ドル$ shows this grid. Travel between two workstations can only occur via the horizontal and vertical paths, and each workstation is exactly 1ドル$ unit away from its four cardinally-adjacent workstations (above, below, right, and left). For instance to go from AA to BB a product must first visit either AB or BA before proceeding on to BB, resulting in a distance of 2ドル$.

Figure 1: The production plant grid layout.

In the current layout, the engineers noticed that products must travel a long distance through the plant to be completed. To optimize the location of the workstations, the company wants to track a single product's travel within the plant. As a start for our tracking software, we need to program an algorithm that answers the following question:

Given the order of workstations that a product has to visit, what is the total distance traveled?

입력

The first line of input is $ \leq N \leq 100,000円,ドル the number of workstations that have to be visited. The remaining $N$ lines are the locations of the workstations in the format [ROW][COLUMN] where [ROW] and [COLUMN] are both single uppercase letters indicating the row and column of the workstation. You can assume that the product is already at the first workstation and will stay at the last workstation.

출력

Output an integer representing the total distance traveled to complete that path.

제한

예제 입력 1

2
AA
CC

예제 출력 1

4

예제 입력 2

3
AA
AB
AC

예제 출력 2

2

예제 입력 3

7
HE
SB
RI
YV
NR
IG
WN

예제 출력 3

94

예제 입력 4

11
BR
XW
BT
SN
UM
IL
OP
VT
ZZ
SU
LR

예제 출력 4

144

예제 입력 5

5
AA
BB
CC
DD
EE

예제 출력 5

8

힌트

출처

School > CS@Mines > CS@Mines HSPC 2024 M번

  • 문제를 만든 사람: Mete Saka
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /