#P10438. [JOIST 2024] 塔楼 / Tower
[JOIST 2024] 塔楼 / Tower
Problem Description
The IOI Tower is an extremely tall tower with a staircase for going up. This staircase has steps, numbered starting from the bottom as step , step , and so on. JOI is currently at step and plans to climb the staircase. JOI can move upward in the following two ways, and moving downward is not allowed.
- Move up by step. This action takes seconds.
- Jump from the current step to the step steps above, skipping the steps in between. This action takes seconds.
Currently, some parts of the staircase are under construction, and steps under construction cannot be stepped on. More precisely, there are construction sections; in the -th section (), the steps under construction are from to .
The IOI Tower has rooms, numbered from to . People can enter room from step of the staircase (). Therefore, JOI decides to determine whether he can reach each room, and if possible, the minimum number of seconds needed.
Given the information about JOI, the construction, and the rooms, write a program that determines whether JOI can reach room (), and if possible, computes the minimum time required.
Input Format
Read the following data from standard input.
- ...
- ...
Output Format
Output lines. On the -th line (), output the minimum number of seconds needed for JOI to reach step ; if it is impossible to reach it, output .
3 1
4 10 35
4 5
10 12
14 14
13
120
5 10
10 1 9
7 11
25 32
37 38
43 44
50 52
6
12
18
24
30
36
42
48
54
60
6
11
17
22
-1
33
-1
44
-1
55
Hint
Sample Explanation 1
JOI can reach step of the staircase in seconds by the following steps:
- Move up from step to step . This takes seconds.
- Move up from step to step . This takes seconds.
- Move up from step to step . This takes seconds.
- Jump from step to step , skipping the steps in between. This takes seconds.
- Move up from step to step . This takes seconds.
- Move up from step to step . This takes seconds.
- Jump from step to step , skipping the steps in between. This takes seconds.
Since it is impossible to reach step in less than seconds, the output is .
This sample input satisfies the constraints of Subtasks .
Sample Explanation 2
This sample input satisfies the constraints of Subtasks .
Constraints
- ()
- ()
- ()
- All given values are integers.
Subtasks
- (5 points) (), ().
- (38 points) , .
- (25 points) , .
- (32 points) No additional constraints.
Translated by ChatGPT 5