Some squares of a table are black, the rest are white. In every white square we write the number of all the black squares having at least one common vertex with it. Find the maximum possible sum of all these numbers.
Solution
The answer is . The sum attains this value when all squares in even rows are black and the rest are white. It remains to prove that this is the maximum value. The sum in question is the number of pairs of differently coloured squares sharing at least one vertex. There are two kinds of such pairs: sharing a side and sharing only one vertex. Let us count the number of these pairs in another way. We start with zeroes in all the vertices. Then for each pair of the second kind we add 1 to the (only) common vertex of this pair, and for each pair of the first kind we add to each of the two common vertices of its squares. For each pair the sum of all the numbers increases by 1, therefore in the end it is equal to the number of pairs. Simple casework shows that (i) 3 is written in an internal vertex if and only if this vertex belongs to two black squares sharing a side and two white squares sharing a side; (ii) the numbers in all the other internal vertices do not exceed 2; (iii) a border vertex is marked with if it belongs to two squares of different colours, and 0 otherwise; (iv) all the corners are marked with 0. Note: we have already proved that the sum in question does not exceed . This estimate is valuable in itself. Now we prove that the numbers in all the vertices cannot be maximum possible simultaneously. To be more precise we need some definitions. Definition. The number in a vertex is maximum if the vertex is internal and the number is 3, or the vertex is on the border and the number is . Definition. A path is a sequence of vertices such that every two consecutive vertices are one square side away. Lemma. In each colouring of the table every path that starts on a horizontal side, ends on a vertical side and does not pass through corners, contains a number which is not maximum. Proof. Assume the contrary. Then if the colour of any square containing the initial vertex is chosen, the colours of all the other squares containing the vertices of the path is uniquely defined, and the number in the last vertex is 0. Now we can prove that the sum of the numbers in any colouring does not exceed the sum of all the maximum numbers minus quarter of the number of all border vertices (not including corners). Consider the squares with a vertex in the lower left corner of the table. The right side and the upper side of such square form a path satisfying the conditions of the Lemma. Similar set of paths is produced by the squares with a vertex in the upper right corner of the table. Each border vertex is covered by one of these paths, and each internal vertex by two. In any colouring of the table each of these paths contains a number which is not maximum. If this number is on the border, it is smaller than the maximum by (at least) and does not belong to any other path. If this number is in an internal vertex, it belongs to two paths and is smaller than the maximum at least by 1. Thus the contribution of each path in the sum in question is less than the maximum possible at least by , q.e.d.