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

34285번 - Golden Landmarks 다국어

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

문제

The city of Golden has many landmarks worth visiting. Before arriving in Golden, you made a list of landmarks you want to visit and the order in which you will visit them. To understand where these landmarks are located, you create a map of Golden and mark each landmark on it. You determine the $x$ and $y$ coordinates of each landmark and plot out your journey for the day. Now, you want to determine the total walking distance required to visit all landmarks in the given order. You will start at the first landmark and finish your walk at the last landmark.

Since Golden is laid out on a grid, the walking distance between two landmarks at coordinates $(x_1, y_1)$ and $(x_2, y_2)$ is $|x_1 - x_2| + |y_1 - y_2|$.

입력

The first line of input contains an integer $n$ ($ 2 \leq n \leq 10^5 $) representing the number of landmarks.

The next $n$ lines each contain a string $ s $ ($ 1 \leq |s| \leq 25 $), the name of a landmark, followed by two integers $x$ and $y$ ($ -10^4 \leq x, y \leq 10^4 $) representing the landmark's coordinates. Each landmark name consists only of uppercase and lowercase Latin letters and is unique.

The final line contains a space-separated sequence of $n$ landmark names, specifying the exact order in which you will visit them. Each landmark appears exactly once in this sequence.

출력

Output a single integer, the total walking distance required to visit all landmarks in the specified order.

제한

예제 입력 1

2
CTLM 1 1
MinesMarket 2 2
MinesMarket CTLM

예제 출력 1

2

예제 입력 2

5
ClearCreek 0 0
MinesM 20 10
SouthTable -20 -10
WoodysPizza 10 10
ColoradoSchoolOfMines 20 -10
ColoradoSchoolOfMines ClearCreek WoodysPizza SouthTable MinesM

예제 출력 2

160

힌트

출처

School > CS@Mines > CS@Mines HSPC 2025 E번

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

출처

대학교 대회

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

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