KnightCircuit2
SRM 564 · 2012-06-05 · by vexorian
Problem Statement
A knight circuit is a sequence of cells on a chessboard that starts and ends with the same cell. Each consecutive pair of cells in the knight circuit must correspond to a single jump of the knight. The knight circuit may visit each cell arbitrarily many times. The size of a knight circuit is the number of different cells visited by the circuit.
You are given the
Constraints
- w and h will each be between 1 and 45000, inclusive.
1 1 Returns: 1
Note that a sequence that consists of a single cell is considered to be a valid knight circuit.
15 2 Returns: 8
If you start at any corner of the board, it is possible to move the knight to visit 8 cells, and then do the same moves in reverse in order to return to the starting cell. One possibility for the first eight cells of an optimal knight circuit is shown below: 1...3...5...7.. ..2...4...6...8
100 100 Returns: 10000
It is possible to make a Knight circuit that contains all the cells on the board.
3 3 Returns: 8
5 4 Returns: 20
Submissions are judged against all 122 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class KnightCircuit2 with a public method int maxSize(int w, int h) · 122 test cases · 2 s / 256 MB per case