Under construction

Still being built. Things may change

Broadcasting Stations

Time limit2.5sMemory limit1024 MB

Summary
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 NN broadcasting stations s_1,s_2,…,s_Ns\_1, s\_2, \dots, s\_N on a straight line. The position of station s_is\_i is a positive integer x_ix\_i. You must assign a broadcast range r_ir\_i to each station s_is\_i. When station s_is\_i broadcasts, the stations within distance r_ir\_i of s_is\_i can receive its signal. In other words, if station s_js\_j lies in the closed interval [x_i−r_i,x_i+r_i][x\_i-r\_i,x\_i+r\_i], then s_js\_j can receive the broadcast of s_is\_i. A broadcast from station s_is\_i can reach station s_js\_j in hh steps, where h>1h > 1, by being relayed through h−1h-1 stations. That is, there exist stations s_i_1,s_i_2,…,s_i_h−1s\_{i\_1}, s\_{i\_2}, \dots, s\_{i\_{h-1}} such that s_is\_i passes the broadcast to s_i_1s\_{i\_1}, each s_i_ks\_{i\_k} passes it to s_i_k+1s\_{i\_{k+1}}, and s_i_h−1s\_{i\_{h-1}} passes it to s_js\_j. Then the broadcast of s_is\_i reaches s_js\_j in hh steps. Of course, when h=1h=1, the broadcast of s_is\_i reaches s_js\_j directly. In these cases, we say that the broadcast of s_is\_i reaches s_js\_j in hh steps. We want to choose one station as an hh-center. This station does not broadcast. It must receive the broadcasts of all other stations within at most hh steps. We call this station an hh-center. The broadcast range of an hh-center is 00. When assigning a range r_ir\_i to each station s_is\_i, the cost of the assignment is the sum of the squares of the ranges. That is, the cost is ∑_i=1Nr_i2\sum\_{i=1}^{N}{r\_i^2}. We assign the ranges so that this cost is minimized. Let C_h\*(s)C\_h^\*(s) be the minimum cost when ss is an hh-center. The goal is to find the hh-center with the smallest C_h\*(s)C\_h^\*(s) among all possible hh-centers ss, together with the range assignment that achieves that minimum cost. Given the positions of NN stations, write a program that outputs, for each h=1,2,…,N−1h=1, 2, \dots, N-1, the minimum value of C_h\*(s)C\_h^\*(s) over all possible hh-centers ss. For example, Figures 1 and 2 below show the case where five stations s_1,…,s_5s\_1, \dots, s\_5 are at coordinates 1,3,4,6,91, 3, 4, 6, 9 and h=2h=2. In Figure 1, assigning the ranges 3,1,5,23, 1, 5, 2 to s_1,s_2,s_3,s_4s\_1, s\_2, s\_3, s\_4 gives a minimum cost of 3939 when s_5s\_5 is the hh-center. In Figure 2, assigning the ranges 2,1,2,32, 1, 2, 3 to s_1,s_2,s_4,s_5s\_1, s\_2, s\_4, s\_5 gives a minimum cost of 1818 when s_3s\_3 is the hh-center. So the smallest minimum cost over all possible hh-centers is 1818. 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 NN and the array X\[0..N−1]X\[0..N-1] of station positions. Here X\[]X\[] is a vector of size NN, the values of X\[i]X\[i] 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 Y\[]Y\[] of size N−1N-1. For i=0,…,N−2i=0,\dots,N-2, Y\[i]Y\[i] is the minimum over all possible (i+1)(i+1)-centers of their minimum cost. This function must be called exactly once inside the stations() function.

Constraints

2≤N≤1202 \le N \le 120, 1≤x_1<x_2<⋯<x_N≤1081 \le x\_1 < x\_2 < \cdots < x\_N \le 10^8

Examples2

  1. Example 1

    Input
    3
    1 3 8
    
    Expected output
    29
    29
    
  2. Example 2

    Input
    5
    1 3 4 6 9
    
    Expected output
    39
    18
    18
    18