Problem Statement
A lame knight is located at the bottom-left corner of a height x width chessboard. Unlike a healthy knight, a lame knight can only make moves where he goes to the right. The only possible moves are:
- 2 cells up, 1 cell right;
- 1 cell up, 2 cells right;
- 1 cell down, 2 cells right;
- 2 cells down, 1 cell right.
Definition
- Class:
- LameKnight
- Method:
- maxCells
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int maxCells(int height, int width)
- (be sure your method is public)
Constraints
- height will be between 1 and 2,000,000,000, inclusive.
- width will be between 1 and 2,000,000,000, inclusive.
Examples
100
50
Returns: 48
1 move of kind 2, 1 move of kind 3, 23 moves of kind 1 and 22 moves of kind 4.1
1
Returns: 1
There are no possible moves here, so the only visited cell is the starting cell.17
5
Returns: 4
It's possible to visit 5 cells (making 4 moves of kind 1 for example), but it's impossible to make it by 4 different moves. So, the best strategy here is to make 3 moves (thus visiting 4 cells).2
4
Returns: 2
20
4
Returns: 4
4 cells can be visited using 2 moves of kind 1 and 1 move of kind 4.