#P10427. [蓝桥杯 2024 省 B] 数字接龙
[蓝桥杯 2024 省 B] 数字接龙
Background
So far, no solution has been found (without special-casing) that can prune effectively and pass the testdata with , . Since this problem is suspected to be wrong, this problem does not provide judging or an editorial section.
Problem Description
Xiao Lan recently became addicted to a maze game called "Number Snake". The game is played on an grid board, where each cell contains an integer between . The rules are as follows.
- Start from the top-left cell , and the goal is to reach the bottom-right cell . At each step, you may move to the next cell in a horizontal / vertical / diagonal direction.
- For the cells visited along the path, in the visiting order, the sequence formed by the numbers on them must be: .
- Along the way, you must visit every cell on the board exactly once (only once).
- The path must not contain crossing segments. For example, if you have moved from to before, then moving from to would make the segments cross, which is not allowed.
For convenience, we label all eight possible moving directions with numbers, as shown in Figure . Therefore, a moving path can be represented by a digit string containing numbers between . As shown in Figure , for a sample maze, the corresponding answer is: .

Now please help Xiao Lan plan a moving path and output it. If there are multiple paths, output the lexicographically smallest one. If there is no such path, output .
Input Format
The first line contains two integers . Then follow lines, each containing integers, representing the numbers on the grid cells.
Output Format
Output one line containing the answer. If there is no valid path, output .
3 3
0 2 0
1 1 1
2 0 2
41255214
Hint
Constraints
- For of the testdata, .
- For all testdata, .
Translated by ChatGPT 5