#BS0000317. Bảo trì các đền thờ (Shrine Maintenance)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bảo trì các đền thờ (Shrine Maintenance)
Shrine Maintenance
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A religious community has circular shrine sites of radius . Each circumference is split into equal arcs, with division points numbered through cyclically. A site has sacred divisors , each a positive proper divisor of . A point houses a shrine precisely when its index is divisible by at least one sacred divisor. There is only one shrine at any such point; let denote their total number.
During maintenance the site is closed, and workers simultaneously leave a shed at the circle's center. Every shrine must be visited by at least one worker, and all workers must return to the center. Travel between visited points is along straight line segments. The site reopens only after the last worker returns.
Find the smallest possible value of the longest individual travel distance over all assignments and routes.



Input
One line contains integers : the worker count, number of equal arcs, number of sacred divisors and the divisors themselves.
Output
Print the optimal maximum travel distance, rounded to exactly one decimal place, including a trailing zero when necessary.
Subtasks
- Subtask 1 (20 points): ; ; ; for all ; , where counts indices divisible by at least one . Rounding to one decimal is unchanged for deviations of at most from the exact optimum.
- Subtask 2 (30 points): ; ; ; for all ; , where counts indices divisible by at least one . Rounding to one decimal is unchanged for deviations of at most from the exact optimum.
- Subtask 3 (50 points): ; ; ; for all ; , where counts indices divisible by at least one . Rounding to one decimal is unchanged for deviations of at most from the exact optimum.
Examples
Input 1
3 12 2 2 3
Output 1
3517.6
Explanation 1
The shrines are at 2,3,4,6,8,9,10,12. Use groups (2,3,4), (6,8,9), (10,12). Each route spends 2000 going to and from the center. The second group adds chords of lengths 1000 and about 517.638, totaling 3517.638. Below this limit, only triples (2,3,4) and (8,9,10) are possible; the remaining shrines 6 and 12 cannot share a route. Thus the rounded optimum is 3517.6.
Input 2
3 6 1 1
Output 2
3000.0
Explanation 2
All six points are shrines. Three adjacent pairs each require two radii plus a chord of 1000. Some worker must visit at least two shrines, and their minimum separation is 1000.
Input 3
1 6 1 1
Output 3
7000.0
Explanation 3
A single worker visits six shrines using five adjacent chords of 1000 and two radii. At least five inter-shrine moves of length at least 1000 are necessary, so the optimum is 7000.
Input 4
8600 8600 3 1 10 100
Output 4
2000.0
Explanation 4
Divisor 1 makes every point a shrine. Assign one of the 8600 workers to each shrine for a round trip of 2000, also a lower bound for visiting any shrine.
Input 5
7 70 3 14 10 35
Output 5
2624.3
Explanation 5
There are 12 shrines. A seven-group assignment is (10,14), (20), (28,30,35), (40,42), (50,56), (60), (70). The longest group (28,30,35) adds chords of gaps 2 and 5 to the two radii, giving about 2624.32049. The other distances are about 2357.1, 2000.0, 2179.3, 2532.1, 2000.0 and 2000.0. The rounded optimum is 2624.3.
Input 6
2 84 3 3 4 14
Output 6
4987.7
Explanation 6
There are 44 shrines. Take two cyclic groups: from shrine 20 through 60 (21 shrines), and from 63 through 84 and onward through 18 (23 shrines). Adding two radii and the consecutive chords gives approximately 4987.74051 and 4913.89899. The larger distance rounds to 4987.7.
Input 7
4 35 2 7 5
Output 7
3224.9
Explanation 7
There are 11 shrines. Use groups (5,7,10), (14,15,20), (21,25), (28,30,35). Their lengths are about 2889.2, 3047.0, 2702.7 and 3224.9. The last group traverses two chords with gaps 2 and 5, plus 2000, giving approximately 3224.88127.
Input 8
3 20 2 5 4
Output 8
3488.4
Explanation 8
The shrines are 4,5,8,10,12,15,16,20. Use (4,5,8), (10,12), (15,16,20), whose route lengths are about 3220.85, 2618.03 and 3488.44. The last route adds chords of gaps 1 and 4 to 2000, totaling approximately 3488.43943.
Input 9
4 6 1 1
Output 9
3000.0
Explanation 9
Six equally spaced shrines can be assigned as two adjacent pairs and two singletons: (1,2), (3,4), (5), (6). Two routes have length 3000, two have length 2000. At least one worker must visit two shrines, and the shortest inter-shrine chord is 1000. Thus 3000.0 is optimal.