Solution:
We denote the centers using the coordinates of the squares, so that the centers of the bottom row are the points (0,0),…,(2019,0) and those of the top row are (0,1),…,(2019,1).
a.
Consider the set of segments S that connect the following pairs of points:
(i) (0,0)−(k,1) for k=1,…,2019;
(ii) (0,0)−(0,1);
(iii) (k,0)−(0,1) for k=1,…,2019.
In the previous list no pair appears twice, hence the corresponding segments are also distinct. Since in the first point we have indicated 2019 pairs, in the second 1 pair, and in the third 2019 pairs, in total those listed are 4039 distinct pairs.
Let us choose any two segments s1,s2∈S. If neither is of type (iii), then s1∩s2=(0,0); similarly, if neither is of type (i), then s1∩s2=(0,1). If instead s1 is of type (i) and s2 is of type (iii), or vice versa, then s1 and s2 are the (internal) diagonals of the convex, non-crossed quadrilateral whose vertices are (0,0),(xs2,0),(xs1,1),(0,1), so they intersect.
Summing up, we have the following two facts:
- ∣S∣=4039
- every pair of segments in S intersects.
If we had at most 4038 colors available, by the pigeonhole principle at least two segments in S would have the same color, but this is incompatible with the requirement that non-disjoint segments have different colors.
b.
Let us enumerate the 4039 colors in this way: −2019,…,−1,0,1,…,2019.
A valid coloring of the segments is the following: the segment between (x1,0) and (x2,1) is colored with color x2−x1.
Let us show that any two segments s1,s2 of the same color c do not intersect. Let (x1,0) be the first vertex of s1: then the second must be (x1+c,1); similarly let (x2,0) be the first vertex of s2, and consequently (x2+c,1) the second. Then s1 and s2 are two opposite sides of the quadrilateral having as vertices (x1,0),(x2,0),(x2+c,1),(x1+c,1). This quadrilateral is a (non-crossed) parallelogram because the other two sides are parallel and have length c. Hence s1 and s2 do not intersect.