CrossWordPuzzle
SRM 268 · 2005-10-18 · by lars2520
Problem Statement
You are in the process of creating a crossword puzzle. You've already designed the board, but now you need to come up with words of various sizes to put in the puzzle. An empty crossword puzzle consists of filled squares ('X') and empty squares ('.'). Here is an example of a board with 5 rows and 6 columns:
X....X
X.XX.X
...X..
X.XX.X
..X...
A "slot" of length N is defined as exactly N empty squares in a row, surrounded on either side by either a filled square or the edge of the board. N must be at least 2. There are five horizontal slots in the example puzzle above:
- First row, length = 4
- Third row, length = 3
- Third row, length = 2
- Fifth row, length = 2
- Fifth row, length = 3
Given a
Constraints
- board will contain between 3 and 50 elements, inclusive.
- Each element of board will contain between 3 and 50 characters, inclusive.
- Each element of board will be the same length.
- board will consist of only '.' and 'X' characters, and will contain at least two '.' characters.
- All '.' characters in board will be connected horizontally or vertically.
- size will be between 2 and 50, inclusive.
{"X....X",
"X.XX.X",
"...X..",
"X.XX.X",
"..X..."}
3
Returns: 2
The example from above. Note that there are two horizontal slots with length = 3.
{"...X...",
".X...X.",
"..X.X..",
"X..X..X",
"..X.X..",
".X...X.",
"...X..."}
3
Returns: 6
There are two slots of length 3 on both the first and seventh rows, and one slot each on the second and sixth rows, for a total of 6.
{".....X....X....",
".....X....X....",
"..........X....",
"....X....X.....",
"...X....X....XX",
"XXX...X....X...",
".....X....X....",
".......X.......",
"....X....X.....",
"...X....X...XXX",
"XX....X....X...",
".....X....X....",
"....X..........",
"....X....X.....",
"....X....X....."}
5
Returns: 8
{"...",
"...",
"..."}
50
Returns: 0
{"....",
"....",
"...."}
3
Returns: 0
Submissions are judged against all 41 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CrossWordPuzzle with a public method int countWords(vector<string> board, int size) · 41 test cases · 2 s / 256 MB per case