Woburn Challenge 2016-17 Round 3 - Senior Division

You've landed a job as one of the level designers for the latest game in the Pokémon series, Pokémon Navy Green! You've always hated those nerdy Pokémon fans, always having fun with their childish Pokémon nonsense, so this is your chance to get back at them.
One of the screens in the game is a grid of cells with
As a level designer, you may decide that some subset of the cells in the
grid should contain trees. The top-left and bottom-right cells may not
contain trees, but any of the others are fair game. The player may not
move into a cell which contains a tree. However, they do have the
ability to teach a move called Cut to one of their Pokémon. Each time
Cut is used, a single tree can be destroyed, allowing the player to move
into its cell. However, Cut may only be used at most
You love the idea of frustrating the player with a subtly impossible
level, but don't want to make your treachery too obvious, for fear of
losing your job before the game gets released. As such, you'd like to
determine the minimum number of trees that must be present on the grid
such that it's impossible for the player to move from the top-left cell
to the bottom-right one, even after optimally using Cut at most
In test cases worth
Input Specification
The first and only line of input consists of three space-separated
integers
Output Specification
Output one line consisting of a single integer – the minimum number of
trees required to make the level impossible, or -1
if no number of trees
will suffice.
Note that the answer may not necessarily fit within a long long
type in C++, or long
in Java).
Sample Input 1
2 5 2
Sample Output 1
6
Sample Explanation 1
One optimal arrangement of trees is shown below (trees are indicated
with #
, while empty cells are indicated with .
):
.###.
.###.
If the players cut down any
Sample Input 2
2 5 4
Sample Output 2
-1
Sample Explanation 2
Even if trees are placed in all
Comments