Given points on grid corners, find the shortest closed fence along cell edges and diagonals that encloses all of them, output as a + b*sqrt(2).
Hard8GeometrySortingImplementationNo attempts yetTime limit2sMemory limit512 MBM-O is a small robot that cleans the floor of the Axiom, a starliner built by the Buy n Large corporation. Tonight the great hall of the Axiom is a mess. Foreign microbes have spread over its floor, and wiping all of them is M-O's job.
The floor of the great hall is an infinite grid of 1×1 cells. The four edges and the two diagonals of every cell are drawn as white segments. Every microbe sits on a corner of a cell.
Cleaning takes a long time, so M-O first builds a fence around the microbes to stop them from spreading to other areas of the ship. M-O places the fence only on white segments, that is, on cell edges and cell diagonals. The fence is a single closed path, and every microbe must lie inside the fence or on the fence itself.
Given the positions of the microbes, find the perimeter of a shortest fence.
The input holds several test cases. Each test case starts with a line holding the number of microbes in the great hall, n (1≤n≤10000). Each of the next n lines holds two integers xi and yi, the coordinates of the i-th microbe. The absolute value of every coordinate is at most 106. The origin is an arbitrary cell corner. Two microbes are allowed to sit on the same corner.
The last line of the input holds a single 0. That line is not a test case.
The perimeter of any fence laid on grid edges and grid diagonals can be written uniquely as a+b2, where a and b are non-negative integers. For each test case, write the two integers a and b on one line, separated by a space, where a+b2 is the perimeter of a shortest fence.
The fence is a closed path. If two parts of the fence overlap, the overlapping part counts twice.