Connection Status:
Competition Arena > TheMatrix
SRM 610 · 2013-12-22 · by rng_58 · Brute Force
Class Name: TheMatrix
Return Type: int
Method Name: MaxArea
Arg Types: (vector<string>)
Problem Statement

Problem Statement

Have you ever had a dream, that you were so sure was real? What if you were unable to wake from that dream? How would you know the difference between the dream world and the real world?



To answer this complex puzzle, one of the questions that must be answered is to find out whether the world that you live in can be represented by a chess matrix.



Cells of a matrix are called adjacent if they share an edge. A matrix of zeroes and ones is called a chess matrix if there are no two adjacent cells that share the same value. Hence, in a chess matrix the zeroes and ones have to alternate in the same way the colors alternate on a chessboard:





You are given a String[] board that represents a rectangular grid of cells, with a 0 or a 1 in each cell. Each character of each element of board will be either '0' or '1'. In this grid we selected some rectangular subgrid that is a chess matrix. Return the largest possible area of the selected subgrid.

Constraints

  • board will contain between 1 and 100 elements, inclusive.
  • Each element of the board is a string containing between 1 and 100 characters, inclusive.
  • All elements of board will have the same length.
  • Each character of each element of board will be either '0' or '1'.
Examples
0)
{"1", 
 "0"}
Returns: 2

The entire board is a chess matrix.

1)
{"0000"}
Returns: 1

The largest possible chess matrix here is just a single cell.

2)
{"01"}
Returns: 2

Again, the entire board is a chess matrix.

3)
{"001",
 "000",
 "100"}
Returns: 2

Each rectangular subgrid is determined by a contiguous range of rows and a contiguous range of columns. The four corners of this grid do not form a valid rectangular subgrid.

4)
{"0"}
Returns: 1

Submissions are judged against all 208 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TheMatrix with a public method int MaxArea(vector<string> board) · 208 test cases · 2 s / 256 MB per case

Submitting as anonymous