#P14452. [ICPC 2025 Xi'an R] Follow the Penguins
[ICPC 2025 Xi'an R] Follow the Penguins
题目描述
There are penguins standing on a number line. The -th penguin is initially located at coordinate . It is guaranteed that all -s are pairwise distinct.
Each penguin chooses a target penguin, denoted by (, ). At time , all penguins start moving simultaneously. Each one runs towards the current position of its target penguin at a constant speed of units per second.
When penguin meets penguin , it stops immediately. For every penguin, determine the time when it stops moving. Here, penguin meets penguin if and only if they are at the same coordinate at the same time.
It can be proven that every penguin will stop moving within a finite amount of time, and the stopping time is always an integer.
输入格式
The first line of the input contains a single integer (), which is the number of penguins.
The second line of the input contains integers (, ), where is the target chosen by the -th penguin.
The third line of the input contains distinct integers (), where is the initial coordinate of the -th penguin.
输出格式
Output a single line containing integers, where the -th integer represents the time (in seconds) when the -th penguin stops moving.
3
2 3 1
-1 2 3
7 1 4
10
8 3 6 7 1 8 2 10 8 1
0 -14 5 -3 14 -12 11 8 -18 17
25 21 17 14 14 49 29 9 61 17
提示
In the example, initially, since the second penguin is in the positive direction of the first penguin, the first penguin runs in the positive direction. Similarly, the second penguin runs in the positive direction, while the third penguin runs in the negative direction. The initial positions of the three penguins on the number line are shown in the figure below:
:::align{center}
:::
At second , the second penguin and the third penguin meet at , at which point the second penguin stops moving.
:::align{center}
:::
At this moment, the first penguin is at , and the second penguin is at . The distance between them is . Since the first penguin runs at a speed of units per second, it will take more seconds to reach the second penguin. Therefore, the first penguin stops moving at second .
Before the first penguin stops, the third penguin meets it at second . So the answers are , , and , respectively.
京公网安备 11011102002149号