Region of Interest - Java
Anonymous User
152

We have a sensor field of NxN square cells. Each sensor reports the “status” of a cell
using an integer. Neighboring cells (cells either above, below, left, or to the right) reporting the same
“status” form a contiguous region. We do not count diagonal cells with the same “status” as part of
the same contiguous region however.

Write software to determine two things:
(1) the size of the maximum contiguous region(i.e., count the number of cells) of the same “status”;
(2) the size of the maximum contiguous region
that shows two different “status”. This kind of contiguous region must have two different “status”, not
just one “status”.

INPUT FORMAT:
The first line of input specifies the size of the sensor field N (where 1≤N≤250). The field is an NxN
square of cells. This is followed by N lines. Each of the N lines contains N integers “status” of the
sensor reading of the cell (the sensor “status” value is between 0 and 10 6 ). The sensor network
designer knows that there are at least two different “status” values that will be produced by the
sensor network in the sensor field.

OUTPUT FORMAT:
Produce two pieces of information in two separate lines: (1) the size of the largest contiguous region
that shows the same “status”; (2) the size of the largest contiguous region that shows two different
“status”.
SAMPLE INPUT:
4
8 3 9 3
4 9 9 2
9 9 2 7
8 2 2 9
SAMPLE OUTPUT:
5
10

Comments (1)