#P4473. [国家集训队] 飞飞侠

    ID: 3405 远端评测题 5000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2011线段树并查集WC/CTSC/集训队O2优化最短路

[国家集训队] 飞飞侠

Description

Fei Fei Country is a legendary land, and its residents are called "Fei Fei Xia" (pinyin).

Fei Fei Country is an N×MN\times M 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 ii, column jj have a fee Ai,jA_{i,j} and a launching capability Bi,jB_{i,j}. We define the distance between two cells sharing an edge to be 11. Then, any Fei Fei Xia only needs to pay Ai,jA_{i,j} at (i,j)(i, j) to jump to any position whose distance from (i,j)(i, j) is no more than Bi,jB_{i,j}. See the figure below. https://cdn.luogu.com.cn/upload/pic/17919.png (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 X,Y,ZX, Y, Z. They decide to gather to play and want to meet at one of their positions. Given the coordinates of the 33 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 XX first, then YY.

Description

Input Format

The first line contains two integers NN and MM, representing the number of rows and columns.

Next are two N×MN\times M matrices of natural numbers, giving Bi,jB_{i,j} and Ai,jA_{i,j}.

The last line contains six numbers, representing the row and column indices of the locations of X,Y,ZX, Y, Z.

Output Format

On the first line, output a single character XX, YY or ZZ, 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 20%20\% of the testdata, N,M10N, M \leq 10, Bi,j20B_{i,j} \leq 20.
  • For 40%40\% of the testdata, N,M100N, M \leq 100, Bi,j20B_{i,j} \leq 20.
  • For 100%100\% of the testdata, 1N,M1501 \leq N, M \leq 150, 0Bi,j1090 \leq B_{i, j} \leq 10^9, 0Ai,j10000 \leq A_{i, j} \leq 1000.

Translated by ChatGPT 5