#P4473. [国家集训队] 飞飞侠
[国家集训队] 飞飞侠
Description
Fei Fei Country is a legendary land, and its residents are called "Fei Fei Xia" (pinyin).
Fei Fei Country is an rectangular grid, where each cell represents a block.
However, there is no transportation in Fei Fei Country. Fei Fei Xia move entirely using ground-based launch devices.
Every block is equipped with a launch device. Using a launch device requires paying a certain fee, and each device has its own launching capability.
Let the launch device at row , column have a fee and a launching capability . We define the distance between two cells sharing an edge to be . Then, any Fei Fei Xia only needs to pay at to jump to any position whose distance from is no more than . See the figure below.
(After paying at the red block, one can jump to any blue block around it.)
The problem is simple. There are three Fei Fei Xia, named . They decide to gather to play and want to meet at one of their positions. Given the coordinates of the Fei Fei Xia, find at which person’s position they should gather to minimize the total cost for all of them. If the minimal costs are the same, prefer first, then .
Description
Input Format
The first line contains two integers and , representing the number of rows and columns.
Next are two matrices of natural numbers, giving and .
The last line contains six numbers, representing the row and column indices of the locations of .
Output Format
On the first line, output a single character , or , indicating the optimal meeting person.
On the second line, output an integer, the minimal total cost.
If gathering is impossible, output only one line NO.
4 4
0 0 0 0
1 2 2 0
0 2 2 1
0 0 0 0
5 5 5 5
5 5 5 5
5 5 5 5
5 5 5 5
2 1 3 4 2 2
Z
15
Hint
Constraints:
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号