Colorful Rectangle
Time limit10sMemory limit512 MB
Given colored points in the plane, find the minimum perimeter of an axis-parallel rectangle that contains at least one point of each of the three colors.
- Level
Hard8 of 10
- Topics
- Segment tree, Sorting, Two pointers
- Solved
- No attempts yet
Problem
Points are given on a plane. Each point is colored red, blue, or green. An axis-parallel rectangle is called colorful if it contains at least one point of every color inside or on its edges. Find the colorful axis-parallel rectangle with the shortest perimeter. An axis-parallel line segment counts as a degenerate rectangle, and its perimeter is twice its length.
Input
The first line contains an integer (). Each of the next lines contains three integers , , and , meaning a point of color is at (, , ). Color 0 is red, 1 is blue, and 2 is green. There is at least one point of every color, and no two points share the same coordinates.
Output
Print a single integer, the shortest perimeter of a colorful axis-parallel rectangle.