555C - Case of Chocolate
Initially there is only one single piece of chocolate. It is the problem's requirement that subsequent same coordinates should return 0
so we can use a set
to store those coordinates. (For example, the sample two has two 10 1
so the second 10 1
should return 0
.
Continuing the concept of pieces, observe that after one valid operation, the chocolate would be split into two (possibly zero area) pieces. For example, in the second sample, the first operation splits the chocolate into x = [1, 1] and x = [3, 10]