luogu#P7901. 「PMOI-0」一笔画
「PMOI-0」一笔画
Background
(Originally LZOI-1. The rename has been approved by PMOI members.)
Problem Description
Yan Zhuo is at a point with coordinates in a matrix.
Now lhm needs to arbitrarily choose a point in the matrix as the starting point, then visit points in order, with the following movement rules:
-
Each move can only choose a point adjacent (up, down, left, or right) to the current point as the target point of this move. Points outside the matrix cannot be chosen.
-
In each round of movement, the path must visit all points in the matrix exactly once, and no point may be visited more than once. After visiting all points, that round of movement ends.
-
Note that after visiting points in order, the last round of movement may not be completed.
Now lhm wants to know: at minimum, how many times will he pass through Yan Zhuo .
Input Format
The first line contains four positive integers .
Output Format
Output one integer on the first line, representing the answer.
2 16 1 1
1
Hint
Sample Explanation

represents Yan Zhuo 's position, and the red line shows lhm's path in the first round.
Constraints
This problem uses bundled testdata.
| Subtask ID | Score | |
|---|---|---|
For all testdata, it is guaranteed that and .
Translated by ChatGPT 5