RectangleAvoidingColoringEasy
Member SRM 485 · 2010-03-12 · by ivan_metelsky
Problem Statement
In a coloring of the board, each cell on the board is colored white or black. A coloring is called rectangle-avoiding if it is impossible to choose 4 distinct cells of the same color so that their centers form a rectangle whose sides are parallel to the sides of the board. In other words, a coloring is rectangle-avoiding if, for each a, b, c, and d with 0 <= a < b < N, 0 <= c < d < M, there is at least one white cell and at least one black cell among the cells (a, c), (a, d), (b, c) and (b, d).
You are given a
Notes
- Two colorings are different if there is a cell on the board that is colored white in one coloring and black in the other coloring.
- The answer will always fit into a 32-bit signed integer data type.
Constraints
- board will contain between 1 and 10 elements, inclusive.
- Each element of board will contain between 1 and 10 characters, inclusive.
- All elements of board will contain the same number of characters.
- Each character in each element of board will be 'W', 'B' or '?'.
{"??",
"??"}
Returns: 14
Since each cell can be black or white, there are 2^4 = 16 ways to color this board. Of them, only 2 monochromatic colorings are not rectangle-avoiding, so the answer is 16 - 2 = 14.
{"B?",
"?B"}
Returns: 3
It is the same board as in previous example, but colors for some cells are already predefined. There are 4 ways to color the remaining cells and in one of them the board becomes completely black. Therefore the answer is 4 - 1 = 3.
{"WW",
"WW"}
Returns: 0
This board is already colored and the coloring is not rectangle-avoiding.
{"??B??",
"W???W",
"??B??"}
Returns: 12
{"?"}
Returns: 2
Submissions are judged against all 168 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class RectangleAvoidingColoringEasy with a public method int count(vector<string> board) · 168 test cases · 2 s / 256 MB per case