#P3438. [POI 2006] ZAB-Frogs
[POI 2006] ZAB-Frogs
Description
A scourge of frogs destroying all the crops has started in Byteotia. A farmer named Byteasar has decided to fight the vermin with peculiar “scarefrogs” that he has set up at certain points of his field. While moving from one place to another, every frog tries to keep as far from them as possible, i.e., it maximizes the distance to the closest scarefrog.
Byteasar’s field is rectangular. The frogs leap in directions parallel to the field’s sides, and each leap has unit length 1. For a given route, the scarefrog-distance is the minimum, over all points visited continuously along the route (including the points between leaps), of the distance to the nearest scarefrog.
Byteasar already knows the most common starting and destination points of the frogs’ routes, so he experiments with various deployments of scarefrogs. He asks you to compute the maximum (over all routes from the start to the target) scarefrog-distance achievable while still reaching the target. We call this value the frogshold distance. You should output the square of this number.
In other words, given a grid with some “bad” points (the scarefrogs), find a path from the start to the end that maximizes the minimum distance, over all points on the path, to the nearest bad point, and output this maximum squared.
Input Format
- The first line contains two integers and — the width and height of the field ().
- The second line contains four integers , , and ; is the frog’s start position, and is the target position (, ).
- The third line contains one integer ().
- Each of the next lines contains two integers and — the coordinates of the -th scarefrog.
- No two scarefrogs occupy the same position, and none of them is at or .
Output Format
Output a single integer — the square of the frogshold distance. If the frog cannot avoid leaping directly onto some scarefrog, output .
5 5
1 1 5 5
2
3 3
4 2
4
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号