Woburn Challenge 2017-18 Finals Round - Senior Division
After weeks of gruelling combat, the unified cow-monkey army has been abruptly called home. Bo Vine and the Head-Monkey have both realized that continuing to fight this war against the Party of Extraterrestrial Gangsters is senseless — if the aliens are provoked into using their devastating vaporization beam, Scarberia is surely doomed. However, they're not prepared to just surrender the Earth to PEG either. Perhaps an alternative resolution can be found? Perhaps an offer of peace can be extended to PEG?
Upon consultation with his leading extraterrestrial linguistics experts,
Bo Vine has devised a plan for communicating with the aliens — using the
universal alien language of crop formations! Crop circles are difficult
to create, but crop rectangles will do just as well. In order to convey
a message of peace, Bo Vine has determined that a sequence of
Unfortunately, having spent just about all of their resources on the war
against PEG, the cows and monkeys are having a hard time finding any
equipment to mow down crops. The Head-Monkey's old lawnmower will have
to do. The lawnmower is able to mow down a
For each crop rectangle, the lawnmower will need to start in the
bottom-left corner of the grid, facing in any cardinal direction of the
Head-Monkey's choice. After that, at any point, the Head-Monkey may
either drive the lawnmower forwards by one cell (in the direction it's
currently facing), or turn it
Much to the Head-Monkey's dismay, her old lawnmower doesn't handle as well as she seemed to remember. In particular, its turning radius is quite lacking, resulting in her needing to drive it forwards at least twice between any two consecutive turns. For example, she may not turn → turn or turn → drive → turn at any point, but she may turn → drive → drive → turn.
For each crop rectangle
The Head-Monkey also doesn't want to risk running out of gas before the
crop formations are complete, lest they accidentally send a message of
war to PEG instead! As such, she'd like to minimize the amount of gas
used. For each independent crop rectangle, help her determine the
minimum amount of gas required to create it, or report a value of -1
if
it's impossible to do so.
Subtasks
In test cases worth
In test cases worth another
Input Specification
The first line of input consists of a single integer,
Output Specification
Output -1
if it's impossible.
Sample Input
3
3 1
3 2
1 1
Sample Output
2
-1
0
Sample Explanation
For the first rectangle, assuming that the lawnmower starts in the bottom-left corner of the grid facing upwards, it can simply drive forwards twice to mow down the remaining two cells.
For the second rectangle, it's possible to mow down up to
Comments