board of odd size n × n; every cell holds a colour 0, 1 or 2.
The letter Y on the board is made of three segments:
- the diagonal from the top-left corner to the centre cell;
- the diagonal from the top-right corner to the centre cell;
- the vertical line from the centre cell down to the bottom edge.
The Y counts as drawn when all its cells share one colour, all remaining cells share one colour too, and those two colours differ.
In one action you can repaint any cell to 0, 1 or 2. Return the fewest actions after which the board shows the Y.board=[[2, 0, 2], [0, 2, 0], [0, 2, 0]] → 0
The Y is already there: its cells hold 2 and every other cell holds 0.
board=[[1, 1, 1], [1, 1, 1], [1, 1, 1]] → 4
Keep the Y as 1s and repaint the four cells outside it, say to 0.
board=[[0, 1, 2, 1, 0], [1, 0, 1, 0, 1], [2, 1, 0, 2, 1], [1, 1, 0, 1, 2], [2, 1, 1, 1, 1]] → 6
board=[[2, 0, 2], [0, 2, 0], [0, 2, 0]]
0
Run checks the first 3 tests in your browser. Submit checks all 76 tests on the server, hidden ones included.