FriendlyRooks
TCO19 SRM 743 · 2018-12-08 · by boba5551
Problem Statement
You have a rectangular chessboard divided into unit squares. Each square is either empty or contains a rook. You are given the
We say that two rooks attack each other if and only if all the following conditions are satisfied:
- The rooks are of different colors.
- They are in the same row or in the same column.
- There are no other rooks between them.
You are going to color all the rooks. We say that a coloring of rooks is friendly if no two rooks attack each other. You want to produce a friendly coloring. What is the maximum number of distinct colors you may use?
Constraints
- board will contain between 1 and 20 elements, inclusive.
- Each element of board will contain between 1 and 20 characters, inclusive.
- All the elements of board will contain the same number of characters.
- Each character of each element of board will be 'R' or '.'.
{".R.R",
"R.R.",
".R.R"}
Returns: 2
The friendly coloring shown below uses two colors (denoted 1 and 2). We can show that there is no friendly coloring with more than two colors. .1.1 2.2. .1.1
{"RRRRRRRRRRRRRRR"}
Returns: 1
All rooks must share the same color.
{"...............",
"...............",
"...............",
"...............",
"...............",
"..............."}
Returns: 0
{"....R..........",
".R...........R.",
"....R..........",
".R........R....",
"....R..........",
"....R.....R...."}
Returns: 1
{"R.........R",
".R.......R.",
"..R.....R..",
"...R...R...",
"....R.R....",
".....R.....",
"....R.R....",
"...R...R...",
"..R.....R..",
".R.......R.",
"R.........R"}
Returns: 6
Submissions are judged against all 70 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FriendlyRooks with a public method int getMinFriendlyColoring(vector<string> board) · 70 test cases · 2 s / 256 MB per case