#abc342e. E - Last Train
E - Last Train
Score: points
问题描述
在 AtCoder 国家,有 个车站:第 1 号车站、第 2 号车站、……、第 号车站。
您将获得关于该国火车的 条信息。第 条信息()由六个正整数组成的元组 表示,对应以下信息:
- 对于每个时刻 ,存在一列火车如下:
- 火车在时间 从车站 出发,并在时间 到达车站 。
除了这些描述的信息外,不存在其他火车,且无法通过任何其他方式在车站之间移动。另外,假设换乘所需的时间可以忽略不计。
令 表示从车站 最晚能够到达第 号车站的时间。更精确地说, 定义为满足以下所有条件的 的最大值:
- 对于所有 ,有
- 对于所有 ,存在一列在时间 从车站 出发并在时间 到达车站 的火车。
- 对于所有 ,有
如果不存在这样的 ,则设置 。
求出 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
In the country of AtCoder, there are stations: station , station , , station .
You are given pieces of information about trains in the country. The -th piece of information is represented by a tuple of six positive integers , which corresponds to the following information:
- For each $t=l _ i,l _ i+d _ i,l _ i+2d _ i,\ldots,l _ i+(k _ i-1)d _ i$, there is a train as follows:
- The train departs from station at time and arrives at station at time .
No trains exist other than those described by this information, and it is impossible to move from one station to another by any means other than by train.
Also, assume that the time required for transfers is negligible.
Let be the latest time at which one can arrive at station from station .
More precisely, is defined as the maximum value of for which there is a sequence of tuples of four integers $\big((t _ i,c _ i,A _ i,B _ i)\big) _ {i=1,2,\ldots,k}$ that satisfies all of the following conditions:
- for all ,
- For all , there is a train that departs from station at time and arrives at station at time .
- for all .
If no such exists, set .
Find .
Constraints
- $1\leq l _ i,d _ i,k _ i,c _ i\leq10 ^ 9\ (1\leq i\leq M)$
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain if , and Unreachable
if .
Sample Input 1
6 7
10 5 10 3 1 3
13 5 10 2 3 4
15 5 10 7 4 6
3 10 2 4 2 5
7 10 2 3 5 6
5 3 18 2 2 3
6 3 20 4 2 1
Sample Output 1
55
56
58
60
17
The following diagram shows the trains running in the country (information about arrival and departure times is omitted).
Consider the latest time at which one can arrive at station from station . As shown in the following diagram, one can arrive at station by departing from station at time and moving as station station station station .
It is impossible to depart from station after time and arrive at station , so .
Sample Input 2
5 5
1000000000 1000000000 1000000000 1000000000 1 5
5 9 2 6 2 3
10 4 1 6 2 3
1 1 1 1 3 5
3 1 4 1 5 1
Sample Output 2
1000000000000000000
Unreachable
1
Unreachable
There is a train that departs from station at time and arrives at station at time . There are no trains departing from station after that time, so . As seen here, the answer may not fit within a integer.
Also, both the second and third pieces of information guarantee that there is a train that departs from station at time and arrives at station at time . As seen here, some trains may appear in multiple pieces of information.
Sample Input 3
16 20
4018 9698 2850 3026 8 11
2310 7571 7732 1862 13 14
2440 2121 20 1849 11 16
2560 5115 190 3655 5 16
1936 6664 39 8822 4 16
7597 8325 20 7576 12 5
5396 1088 540 7765 15 1
3226 88 6988 2504 13 5
1838 7490 63 4098 8 3
1456 5042 4 2815 14 7
3762 6803 5054 6994 10 9
9526 6001 61 8025 7 8
5176 6747 107 3403 1 5
2014 5533 2031 8127 8 11
8102 5878 58 9548 9 10
3788 174 3088 5950 3 13
7778 5389 100 9003 10 15
556 9425 9458 109 3 11
5725 7937 10 3282 2 9
6951 7211 8590 1994 15 12
Sample Output 3
720358
77158
540926
255168
969295
Unreachable
369586
466218
343148
541289
42739
165772
618082
16582
591828
update @ 2024/3/10 01:36:52