#P8224. [WFOI - 02] I wanna cross the grid(穿越网格)
[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 rows and columns. Rows and columns are numbered starting from . Define an ordered pair to represent the cell at row , column . In each row, the cells from column to column are required areas. Formally, let be the set of required areas, then .
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 , then kid can move to .
Initially, kid is at (it is guaranteed that ). 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 , which must satisfy: for all , there exists such that , and for all , .
Meanwhile, kid must record a clearing sequence . 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, must contain a subsequence of length to be a valid clearing sequence and truly clear the level. Formally, is valid if and only if there exists a sequence of length such that , and is strictly increasing.
Also, to reduce the operation difficulty for lindongli2004, lindongli2004 hopes that kid uses as few steps as possible.
Given , 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 positive integers , representing the number of rows and columns of the grid, the left and right boundaries of the required area, the starting and coordinates, the length of sequence , and the scoring parameter.
The second line contains distinct positive integers, representing the sequence .
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 indicating the path length. Then output lines, each with two positive integers 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
, , and for the rest see the provided files.
Scoring Rules
The last number in the first line of the provided files is . Let your number of steps be . Then:
- If , you will get points.
- If and you can clear the level, you will get points.
- If you cannot clear the level, you will get points.
Checker
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 . That is, your solution cannot contain more than numbers.
Translated by ChatGPT 5