영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
Problem
A rapidly growing sport is indoor orienteering, where the largest competitions attract thousands of participants running around places like a campus. Through the organizers' carefully planned barriers, it becomes a labyrinthine challenge to navigate between control points. Often, it is essential to optimize the use of stairs, and this is what we will focus on in this task. Given a map divided into N areas, you are to calculate the minimal number of stair runs the orienteer needs to make to visit the N areas in sequence (to reach a control point in each).
The building contains several vertical stairwells labeled with letters. Each area is located on a certain floor and is connected to one or more stairwells. A stairwell does not need to be connected to an area on every floor. For example, stairwell B can connect an area on floor 1 with another area on floor 3, without being connected to any area on the intermediate floor 2. Moving one floor up or down in a stairwell costs one time unit. However, we do not care about the time it takes to move within an area and find the control point.
Input
The first line contains the integer N (3 ≤ N ≤ 15), the number of areas.
The next N lines each describe one area. Each line starts with the floor that the area is located at (an integer between 1 and 100), followed by a string with at least one letter, each letter being chosen from A-Z, which describes the stairwells the area is connected to.
Output
Print an integer: the minimal time required to visit all the N areas in the order given in the input, starting in area 1 and ending in area N.
Scoring
Your solution will be tested on a set of test groups. To earn points for a group, you must pass all test cases in that group.
| Group | Points | Constraints |
|---|---|---|
| 1 | 20 | All strings are a single A. |
| 2 | 80 | No additional constraints. |
Explanation of Samples
(그림은 원문 저장소에서 볼 수 있습니다)
Figure 1: Cross-section of the building in example 2. The large numbers indicate floor numbers, and the small ones indicate the numbering of the areas. One possible shortest path through the entire course is: AAD – EEE – CBAA – DEE – EEDD – DAAB – CFF Note that the control points must be visited in order.
In the second example, there is a path with 24 steps (the letters indicate which staircase was used at each step).
예제
예제 1
3 2 A 100 A 3 A
195
예제 2
8 1 AB 4 DE 1 CEF 3 AD 2 E 2 D 2 BC 3 F
24