| Winter Cup 6.0 Online Mirror Contest |
|---|
| Finished |
Since getting his job at Iceberg Corporation, Rami has been ignoring his tasks and playing a new game called Grid Crash. It is a game played on a grid $$$G$$$ of size $$$n\times m.$$$ Each cell in the grid either has some colour, or is empty.
Initially, each cell $$$(i,j)$$$ in the grid contains some color $$$c_{i,j}.$$$ The grid itself contains at most 4 distinct colours.
Now the game is played as follows:
Now, Rami wants to finish the game in the fewest moves possible. Please help him.
A single integer $$$r:$$$ the minimum number of moves to win the game.
5 5 BWBBB WWBWW BWBWB BWBBB WWWWW
3
5 5 RRRRR GGRBB RRRRR ARRRA ARRRA
4
5 5 GGGGG GRRRR GGGGG GRRRR GGGGG
2
It is guaranteed that the grid does not contain more than 4 distinct colours.
The following example shows a sequence of moves that solves the first game (test case 1) in $$$3$$$ moves. It can be shown that it is optimal:
| Name |
|---|


