#P8224. [WFOI - 02] I wanna cross the grid(穿越网格)

    ID: 9159 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>洛谷原创提交答案Special JudgeO2优化模拟退火随机调整其它技巧构造洛谷月赛

[WFOI - 02] I wanna cross the grid(穿越网格)

Background

People who believe in miracles are greater than miracles themselves.

Suddenly, the save point dropped into a huge grid. Only after walking through all required areas will the next save point appear...

Problem Description

You are given a grid with nn rows and mm columns. Rows and columns are numbered starting from 11. Define an ordered pair (x,y)(x,y) to represent the cell at row xx, column yy. In each row, the cells from column LL to column RR are required areas. Formally, let DD be the set of required areas, then D={(x,y)1xn,LyR,x,yN+}D=\{(x,y)|1\leq x\leq n,L\leq y\leq R,x,y\in N_+\}.

Each time, kid can move one step in one of the four directions: up, down, left, or right, and cannot go out of bounds. Formally, if kid is currently at (x,y)(x,y), then kid can move to (x+1,y),(x,y+1),(x1,y),(x,y1)(x+1,y),(x,y+1),(x-1,y),(x,y-1).

Initially, kid is at (Sx,Sy)(S_x,S_y) (it is guaranteed that Sy=LS_y=L). He needs to walk through all required areas, and any cell can be visited at most once. Formally, kid’s path is a sequence of ordered pairs P=(x1,y1),(x2,y2)...(xk,yk)P=(x_1,y_1),(x_2,y_2)...(x_k,y_k), which must satisfy: for all (x0,y0)D(x_0,y_0)\in D, there exists i[1,k]i\in[1,k] such that (x0,y0)=(xi,yi)(x_0,y_0)=(x_i,y_i), and for all iji\not= j, (xi,yi)(xj,yj)(x_i,y_i)\not= (x_j,y_j).

Meanwhile, kid must record a clearing sequence pp. After kid enters the required area of a certain row for the first time, he must append that row number to the end of the current sequence, and immediately traverse all required areas of that row. Also, pp must contain a subsequence qq of length LqL_q to be a valid clearing sequence and truly clear the level. Formally, pp is valid if and only if there exists a sequence cc of length LqL_q such that pci=qip_{c_i}=q_i, and cc is strictly increasing.

Also, to reduce the operation difficulty for lindongli2004, lindongli2004 hopes that kid uses as few steps as possible.

Given n,m,L,R,Sx,Sy,qn,m,L,R,S_x,S_y,q, please plan a clearing route for kid, or tell him that no such route exists. The remaining operations will be left to lindongli2004!

Input Format

The first line contains 88 positive integers n,m,L,R,Sx,Sy,Lq,sn,m,L,R,S_x,S_y,L_q,s, representing the number of rows and columns of the grid, the left and right boundaries of the required area, the starting xx and yy coordinates, the length of sequence qq, and the scoring parameter.

The second line contains LqL_q distinct positive integers, representing the sequence qq.

Output Format

The first line outputs a string YES or NO indicating whether a path exists (without quotes).

If a path exists, the second line outputs a positive integer cntcnt indicating the path length. Then output cntcnt lines, each with two positive integers x,yx,y representing the coordinates on the path.

5 4 2 3 2 2 2 15
3 1
YES
15
2 2
2 3
3 3
3 2
4 2
4 3
5 3
5 2
5 1
4 1
3 1
2 1
1 1
1 2
1 3

Hint

Constraints

1LRm1\leq L\leq R\leq m, 1Sxn1\leq S_x\leq n, and for the rest see the provided files.

Scoring Rules

The last number in the first line of the provided files is ss. Let your number of steps be cntcnt. Then:

  • If cntscnt\leq s, you will get 1010 points.
  • If cnt>scnt> s and you can clear the level, you will get 9cntsn29- \frac{cnt-s}{\lfloor\frac{n}{2}\rfloor} points.
  • If you cannot clear the level, you will get 00 points.

Checker

Self-service.

How to use: In the same directory, put the provided testdata into data.in, put your output into data.out, compile and run.

Notes:

  • This checker assumes there exists a solution by default, and checks whether that solution is valid.
  • The maximum capacity of solutions for this checker is 2.5×1082.5 \times 10^{8}. That is, your solution cannot contain more than 2.5×1082.5 \times 10^{8} numbers.

Translated by ChatGPT 5