Burning

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Burning

Time limit: 1 seconds

Memory limit: 512 megabytes

Problem Statement

The ACM laboratory can be represented by a nmn * m grid diagram. Bing's seat is at cell (a,b)(a,b) and Frank's seat is at cell (c,d)(c,d).

In this grid, each cell (x,y)(x,y) has an ignition point ax,ya_{x,y}. If one cell (x,y)(x,y) is on fire, the flame will continuously try to spread to its upper (x,y+1)(x,y+1), lower (x,y1)(x,y-1), left (x1,y)(x-1,y) and right (x+1,y)(x+1,y) cells. The adjacent cell will catch fire immediately if the temperature of the flame is greater or equal to its ignition point and the temperature of this cell will be the same as where the fire came from.

It may be that the weather in Fuzhou is too hot or Bing is too hot, Bing's seat is on fire automatically. What's worse, the temperature of the flame increases by one degree per second and the fire could not be put out for some reason.

Bing wants to know what the temperature is when the fire reaches the Frank's seat so he can calculate how much time is left before Frank realizes and starts to kill him. Note that the initial temperature of the fire is the ignition point of Bing's seat.

Input

The first line contains two integers n,m(1n,m500)n,m(1 \leq n,m \leq 500).

The second line contains four integers a,b,c,d(1a,cn,1b,dm)a,b,c,d(1 \leq a,c \leq n,1 \leq b,d \leq m) denoting Bing's seat (a,b)(a,b) and Frank's seat (c,d)(c,d).

In the following nn lines, each line containing mm integers. The jj-th integer in the ii-th line is ai,j(1ai,j109)a_{i,j}(1 \leq a_{i,j} \leq 10^9) denoting the ignition point of cell (i,j)(i,j).

Output

Print a single integer, denoting the answer to the question.

2 2 
1 1 2 2
6 10
3 3
6
3 4
2 2 2 3
1 2 5 6
4 6 9 5
3 8 2 4
9

福建师范大学第十九届程序设计竞赛正式赛

未参加
状态
已结束
规则
ACM/ICPC
题目
13
开始于
2022-5-22 9:00
结束于
2022-5-22 14:00
持续时间
5 小时
主持人
参赛人数
25