You have a large rectangular piece of chocolate. As usual, the piece of chocolate is divided into squares.
The piece you have is W squares wide and H squares tall.
For the purpose of this problem the squares will be numbered from (1,1) in the upper left corner to (W,H) in the lower right corner of the chocolate.
You can break the chocolate into smaller rectangular pieces. In each step, you can take one of the pieces you have, select one of the lines between the squares (either a horizontal or a vertical one) and break the piece into two new pieces along the line.
A few of the cells are special. Their coordinates are given as int[]s sx and sy: for each i, the square at (sx[i],sy[i]) is special.
You want to eat all special squares and no other squares. Before you can do this, you have to break the chocolate into several pieces in such a way that each piece either consists of special squares only, or it consists of non-special squares only.
Compute and return the minimum number of steps needed in order to break the chocolate correctly.
|