Pixelated

From programming_contest
Jump to navigation Jump to search

This problem gives you a grid and a specification of "pulses" of a given width traversing the grid either upward or rightward. It asks us to count the number of times the pulses in the orthogonal directions collide.

We should be able to see that a pulse at a column X at time T is equivalent to a pulse at column X-1 at time T-1. when it comes to collisions. This means we can shift each pulse to either the first row and column by "time shifting" it accordingly. At this point, we process the pulse begins and ends in order by time, and track how many are "open" in each direction. When a new pulse starts, we can see how many are "open" in the other direction and add that to the total.

The biggest challenge to this problem is figuring out how to process the 4 separate events (xstart, xend, ystart, yend) nicely, as well as ensuring we deal with signals which start and stop at the same time appropriately (end signals should be processed first). Lastly, the answer can be quite large, so longs must be used to count.

There are two problems which are similar, which I cannot exactly identify. One is "frogger" of some sort, and another involves crossing a road between cars. If you come across them, feel free to link them here!