Binary Grid (binarygrid)

25 teams scored 628 points on this task, for a maximum score of 100, an average score of 25 and a median score of 22.

Highlights

  1. Liceo Scientifico Calini, Brescia is the institute with the most points (100).
  2. Lombardia is the region with the most points (166).

Statement

You are given a grid A consisting of N rows and M columns, containing only 0s and 1s. You can do the following operations on A: (1) Select a row i (0 < i < N - 1) and invert it (i.e. flip every value in that row, such that each 0 becomes a 1 and each 1 becomes a 0). (2) Select a column j (0 < j < M - 1) and invert it. A binary grid is beautiful if there are no three consecutive equal values in the same row or in the same column. More formally, there is no i, j (0 < i < N - 1, 0 < j < M - 3) such that A_i, j = A_i, j + 1 = A_i, j + 2, and there is no i, j (0 < i < N - 3, 0 < j < M - 1) such that A_i, j = A_i + 1, j = A_i + 2, j. Your task is to decide whether it is possible to make a given grid beautiful, and if so, then report the minimum number of operations to do it.