ChessboardPattern
SRM 333 · 2007-01-04 · by misof
Problem Statement
A chessboard pattern is a pattern that satisfies the following conditions:
- The pattern has a rectangular shape.
- The pattern contains only the characters '.' (a dot) and 'X' (an uppercase letter X).
- No two symbols that are horizontally or vertically adjacent are the same.
- The symbol in the lower left corner of the pattern is '.' (a dot).
You are given two
Constraints
- rows will be between 1 and 50, inclusive.
- columns will be between 1 and 50, inclusive.
8
8
Returns: {"X.X.X.X.", ".X.X.X.X", "X.X.X.X.", ".X.X.X.X", "X.X.X.X.", ".X.X.X.X", "X.X.X.X.", ".X.X.X.X" }
A standard chessboard. Note that the last element starts with a dot.
1
20
Returns: {".X.X.X.X.X.X.X.X.X.X" }
A single row is a special case of a rectangle.
5
1
Returns: {".", "X", ".", "X", "." }
And so is a single column.
5
13
Returns: {".X.X.X.X.X.X.", "X.X.X.X.X.X.X", ".X.X.X.X.X.X.", "X.X.X.X.X.X.X", ".X.X.X.X.X.X." }
1
1
Returns: {"." }
Submissions are judged against all 33 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ChessboardPattern with a public method vector<string> makeChessboard(int rows, int columns) · 33 test cases · 2 s / 256 MB per case