Rectangular colonies on a grid evolve each second by a north-and-west neighbor rule, and the task asks when every cell becomes empty.
Hard8Dynamic programmingMatrixNo attempts yetTime limit5sMemory limit512 MBBacteria live on an infinite grid of cells. A cell holds at most one bacterium.
Every second the following two changes happen at the same time.
At the start the grid holds a positive, finite number of bacteria, and the occupied cells form one or more rectangular regions.
Determine how many seconds pass before all the bacteria die.
The grid below starts with six bacteria and is empty after 6 seconds. A 1 is a cell with a bacterium and a 0 is an empty cell. The leftmost column is X = 1 and the top row is Y = 1.
t = 0 t = 1 t = 2 t = 3 t = 4 t = 5 t = 6
000010 000000 000000 000000 000000 000000 000000
011100 001110 000110 000010 000000 000000 000000
010000 011000 001100 000110 000010 000000 000000
010000 010000 011000 001100 000110 000010 000000
000000 000000 000000 000000 000000 000000 000000
The first line contains C, the number of test cases.
Each test case is then given in the following format.
The rectangles may overlap.
North is the direction of decreasing Y coordinate, and west is the direction of decreasing X coordinate.
For each test case, print one line in the form Case #N: T, where N is the test case number starting from 1 and T is the number of seconds until all the bacteria die.