#P10548. Planetary Syzygy Index Calculation
Planetary Syzygy Index Calculation
Planetary Syzygy Index Calculation
In an ideal planetary system, n planets orbit a single star in uniform circular motion on the same plane. It is known that at time t = 0 all planets are aligned along a ray originating from the star. The orbital period of the i-th planet is given as ti years, where the periods are provided as positive integers in increasing order. Moreover, for the purpose of this problem, assume that 1 year is not necessarily an integer multiple of ti but that ti divides 1 in the sense that the fractional syzygy events can be unambiguously determined as described below.
For each planet, a syzygy (alignment) event occurs whenever the planet is collinear with the star; in this simplified setting the event times for planet i occur at multiples of ti/2 years. (Note that at time 0 each planet is in alignment; subsequent events will occur at ti/2, ti, etc. But only those events that fall in the half‐open interval [0, 1) year are considered.)
At any given moment t in [0, 1), several planets may simultaneously align with the star. If a set of planets are all collinear with the star along the same ray (i.e. they share the same angular direction modulo \(\pi\)), they form one syzygy event. The event’s rarity is determined by the number of bodies on the line (including the star). In particular, if exactly x planets (excluding the star) are aligned on one ray at the same time, then the rarity for that event is the constant \(w_{x+1}\).
The Syzygy Index of the planetary system is defined as the sum of the rarities of all distinct syzygy events occurring in the interval [0, 1) years.
Simplification for this problem:
- Observe that every planet contributes an alignment at t = 0. Since all n planets are aligned at t = 0, they form a single event with rarity \(w_{n+1}\).
- For t > 0, note that a planet will have another alignment in [0, 1) if and only if its period ti satisfies ti/2 < 1. Because the periods are positive integers, the only possibility for this is ti = 1 (since if ti > 1 then ti/2 ≥ 1). Thus, only planets with ti = 1 will contribute a second alignment at t = 0.5. All such planets that align at t = 0.5 form a separate event with rarity \(w_{(c+1)}\), where c is the number of planets with period 1.
Your task is to compute the system's Syzygy Index over one year.
inputFormat
The input consists of three lines:
- An integer
n
(1 ≤ n ≤ 10), the number of planets. n
space‐separated positive integers representingt1, t2, …, tn
— the orbital periods (in years) of the planets. These are given in increasing order.n
space‐separated integers representing the rarity constantsw2, w3, …, wn+1
. Here,wx
(for x = 2, 3, …, n+1) is the rarity of an event in which exactly (x-1) planets (apart from the star) are aligned.
Note: For the purpose of this problem, a planet will have two alignment events in [0, 1) if and only if its period is 1. All other planets contribute only the alignment at t = 0.
outputFormat
Output a single integer — the Syzygy Index, which is the sum of the rarities of all distinct syzygy events in [0, 1) years.
Computation Details:
- The alignment at t = 0 always involves all n planets, yielding a rarity of
wn+1
(the last constant provided). - If there are c planets with period 1, they will additionally align at t = 0.5, forming a separate event with rarity
wc+1
. - The final answer is the sum:
wn+1 + (if c > 0 then wc+1 else 0)
.
sample
3
1 2 2
10 20 30
40