#2749. 【算法1-7】马的遍历

【算法1-7】马的遍历

说明

有一个 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>�</mi><mo>×</mo><mi>�</mi></mrow></semantics></math>n×m 的棋盘,在某个点 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mi>�</mi><mo separator="true">,</mo><mi>�</mi><mo stretchy="false">)</mo></mrow></semantics></math>(x,y) 上有一个马,要求你计算出马到达棋盘上任意一个点最少要走几步。

比如下图的情况,马从左上角开始只能跳到绿色 1 的地方,从绿色 1 开始只能跳到橙色 2 的地方,以此类推。

而中间红色的部分是走不到的,标记为 -1

输入格式

输入只有一行四个整数,分别为 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>�</mi><mo separator="true">,</mo><mi>�</mi><mo separator="true">,</mo><mi>�</mi><mo separator="true">,</mo><mi>�</mi></mrow></semantics></math>n,m,x,y

输出格式

一个 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>�</mi><mo>×</mo><mi>�</mi></mrow></semantics></math>n×m 的矩阵,代表马到达某个点最少要走几步(不能到达则输出 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>−</mo><mn>1</mn></mrow></semantics></math>1

每个数字占5格位宽,并且空格在后面。

样例

3 3 1 1
0    3    2    
3    -1   1    
2    1    4    

提示

数据范围:

对于全部的测试点,保证 

<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>≤</mo><mi>�</mi><mo>≤</mo><mi>�</mi><mo>≤</mo><mn>400</mn></mrow></semantics></math>1xn400<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>≤</mo><mi>�</mi><mo>≤</mo><mi>�</mi><mo>≤</mo><mn>400</mn></mrow></semantics></math>1ym400