#BS0000426. Thoát khỏi vùng địch (Escape from Enemy Territory)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thoát khỏi vùng địch (Escape from Enemy Territory)
Escape from Enemy Territory
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A group of soldiers has finished its mission and must travel from its current location to a rendezvous point. The map shows every enemy base in the area. The group wants to stay as far from these bases as possible throughout the journey.
The map is a rectangular grid with positions along the -axis and positions along the -axis. Each cell has integer coordinates , where and . A step moves to a horizontally or vertically adjacent cell without leaving the grid.
The Manhattan distance between cells and is
The safety of a route is the minimum distance between any cell on the route, including both endpoints, and any enemy base. Its length is the number of steps. Base cells are not removed from the grid; visiting one makes the route's safety .
Find the greatest achievable safety, then the shortest route length among all routes achieving that safety.
Input
The first line contains three integers : the number of bases and the two grid dimensions.
The second line contains four integers , specifying the start and the rendezvous point .
Each of the next lines contains two integers , the location of base ().
Output
Print two integers on one line, separated by a space: the maximum achievable safety and the minimum route length attaining that safety, in that order.
Subtasks
- Subtask 1 (20 points): ; ; ; for every . All coordinate pairs are distinct.
- Subtask 2 (30 points): ; ; ; for every . All coordinate pairs are distinct.
- Subtask 3 (50 points): ; ; ; for every . All coordinate pairs are distinct.
Examples
Input
1 2 2
0 0 1 1
0 1
Output
1 2
Explanation
The grid has one base at . The route from through to has distances , , and from that base. The start is only one unit from the base, so no route can have safety greater than . The endpoints have Manhattan distance , making two steps optimal.
Input
2 5 6
0 0 4 0
2 1
2 3
Output
2 14
Explanation
The bases are at and . Every route from to must visit a cell with . At this coordinate, the nearest-base distances for are , respectively. Hence safety cannot exceed .
Travel to in five steps, then to in four steps, and finally to in five steps. Every visited cell is at least two units from each base. The total is steps.
Any route with safety must visit . Increasing from zero to five and returning to zero takes at least ten steps, while increasing from zero to four requires at least four more. Thus no equally safe route can use fewer than fourteen steps.