Broadcasting Stations
Time limit2.5sMemory limit1024 MB
For each h, find the minimum total of squared broadcast ranges over all choices of an h-center among N stations on a line.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
There are broadcasting stations on a straight line. The position of station is a positive integer . You must assign a broadcast range to each station . When station broadcasts, the stations within distance of can receive its signal. In other words, if station lies in the closed interval , then can receive the broadcast of . A broadcast from station can reach station in steps, where , by being relayed through stations. That is, there exist stations such that passes the broadcast to , each passes it to , and passes it to . Then the broadcast of reaches in steps. Of course, when , the broadcast of reaches directly. In these cases, we say that the broadcast of reaches in steps. We want to choose one station as an -center. This station does not broadcast. It must receive the broadcasts of all other stations within at most steps. We call this station an -center. The broadcast range of an -center is . When assigning a range to each station , the cost of the assignment is the sum of the squares of the ranges. That is, the cost is . We assign the ranges so that this cost is minimized. Let be the minimum cost when is an -center. The goal is to find the -center with the smallest among all possible -centers , together with the range assignment that achieves that minimum cost. Given the positions of stations, write a program that outputs, for each , the minimum value of over all possible -centers . For example, Figures 1 and 2 below show the case where five stations are at coordinates and . In Figure 1, assigning the ranges to gives a minimum cost of when is the -center. In Figure 2, assigning the ranges to gives a minimum cost of when is the -center. So the smallest minimum cost over all possible -centers is .
Figure 1.
Figure 2.
Implementation
You must implement the following function for the administrator. void stations(int N, int X[]) ; takes the number of stations and the array of station positions. Here is a vector of size , the values of are all distinct, and they are stored in ascending order. Inside the stations() function, you must submit your answer with the following function. void answer(long long Y[]) submits a vector of size . For , is the minimum over all possible -centers of their minimum cost. This function must be called exactly once inside the stations() function.
Constraints
,