#P2867. Optimal Placement for Maximum Square
Optimal Placement for Maximum Square
Optimal Placement for Maximum Square
Farmer John’s cows are taking part in a contest against Farmer Bob’s cows. They are placed on an square lattice (with points having integer coordinates from 0 to ) and no two cows share the same point. Each farm aims to form a square with maximum area using four of its cows as vertices (the square does not have to be axis‐aligned). All of John’s cows are already placed on the grid except for his prized cow, Bessie. Your task is to determine where to place Bessie (on a currently empty point) so that the maximum square (which is formed using any four of John’s cows, and Bessie does not necessarily have to be one of the square’s vertices) has the largest possible area.
We define the area of a square with side length as . In particular, if two points and are adjacent vertices of a square, then the square’s area is given by: [ \text{Area} = (x_2-x_1)^2+(y_2-y_1)^2. ]
The input provides the grid size , the number of John’s pre-placed cows (excluding Bessie), and the number of Bob’s cows . Then follow lines of coordinates for John’s cows and lines for Bob’s cows.
Your goal is to output the maximum area of a square that can be formed (after optimally placing Bessie) using only the points occupied by John’s cows. If no square can be formed, output 0.
inputFormat
The first line contains three integers: , , and , where , , and . The next lines each contain two integers and (with ) representing the coordinates of John’s cows (excluding Bessie). The following lines each contain two integers and representing the coordinates of Bob’s cows. It is guaranteed that no point is occupied by more than one cow.
outputFormat
Output a single integer denoting the maximum area of a square that can be formed by John’s cows (after optimally placing Bessie), where the area is calculated as $$(x_2-x_1)^2+(y_2-y_1)^2$$ for any adjacent vertices of the square. If no square can be formed, output 0.
sample
3 3 1
0 0
0 1
1 0
2 2
1
</p>