Problem D
Drone Diversion
At large programming contests there are often hundreds of participants competing. Every now and then a contestant may need some extra energy to solve a particularly difficult problem. Usually, this happens by ingesting some candy. As a contest organizer, fetching candy to hundreds of contestants requires having tens of so-called runners at your disposal to deliver the candy to a contestant’s desk. After playing around with an old quadcopter during their free time, the organizers of the Swedish Coding Cup had a brilliant idea – what if autonomous drones could deliver candy to the contestants?
Of course, having a bunch of drones flying around is bound to result in some crashes unless they have some careful object avoidance logic. The Coding Cup organizers are almost finished writing this, but decided to outsource a key piece of functionality to you. Since drones have a limited amount of battery and processing power, it’s preferable to run the algorithms to avoid crashes as seldom as possible. An optimization they came up with is to, after two drones located at two given positions have been assigned destinations, check whether the drones will crash no matter what route they take (then trying to avoid each other is pointless), and whether there are any routes where the drones could crash (otherwise they never need to avoid each other).
All drones fly at the same height, so we can consider their positions to be integers $(x, y)$ in the contest hall, which is a rectangle where $x$ is between $0$ and $W - 1$ and $y$ is between $0$ and $H - 1$. When a drone flies from position $(x_ s, y_ s)$ to $(x_ d, y_ d)$, it does so by every second moving one step along either the $X$-axis or the $Y$-axis. Furthermore, drones always fly the shortest possible path to conserve battery, so it takes exactly $|x_ s - x_ d| + |y_ s - y_ d|$ seconds for it to reach its destination. Two robots crash if they after any number of whole seconds occupy the same position. After a drone reaches its final position, it is will stay there for at least the time it takes for the other drone to reach its final position.
Write a program that, given the starting point and destination of two drones, determines whether they will crash no matter what shortest path they take, and whether they will never crash no matter what shortest path they take.
Input
The first line contains an integer $Q$ ($1 \le Q \le 100\, 000$), the number of test cases in a single file. Then follows three lines per test case.
The first line of the test case contains the integers $W$ and $H$ ($1 \le W, H \le 10^9$), the dimensions of the room.
The second line contains the starting position $x_{s_1}, y_{s_1}$ and destination $x_{d_1}, y_{d_1}$ of the first drone, and the third and final line contains the starting position $x_{s_2}, y_{s_2}$ and destination $x_{d_2}, y_{d_2}$ of the second drone ($0 \le x_ i < W$, $0 \le y_ i < H$).
No drone starts at its destination, and the starting positions of the drones are different.
Output
For each test case, output a single line.
If the robots crash no matter what path they take, output IMMINENT DISASTER, if the robots can take paths that would cause a crash, output MAYHEM POSSIBLE, otherwise output CRISIS AVERTED.
Scoring
Your solution will be tested on a set of test groups, each worth a number of points. To get the points for a test group you need to solve all test cases in the test group.
Group |
Points |
Constraints |
$1$ |
$15$ |
$x_{s_1} = x_{d_1}$ and $y_{s_2} = y_{d_2}$ |
$2$ |
$16$ |
$W = 1$ |
$3$ |
$20$ |
$W, H \le 50$, $Q \le 150$ |
$4$ |
$34$ |
$W, H \le 1\, 000$, $Q \le 1000$ |
$5$ |
$15$ |
No additional constraints |
Sample Input 1 | Sample Output 1 |
---|---|
4 1 3 0 0 0 2 0 2 0 0 2 2 0 0 0 1 1 0 1 1 2 2 0 0 1 1 1 1 0 0 1 2 0 0 0 1 0 1 0 0 |
IMMINENT DISASTER CRISIS AVERTED MAYHEM POSSIBLE CRISIS AVERTED |