Golden Landmarks
면접 대비시간 제한1초메모리 제한2048 MB
이름과 격자 좌표가 주어진 n개의 랜드마크를 정해진 순서로 방문할 때, 연속한 두 지점 사이의 맨해튼 거리를 모두 더해 출력한다.
문제
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 and 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 and is .
입력
The first line of input contains an integer () representing the number of landmarks.
The next lines each contain a string (), the name of a landmark, followed by two integers and () 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 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.