首先到每个点的速度实际上是一个定值,就是v0*2^(起点与当前点高度差)
所以当前点i到任意一个相邻点的时间都是一个定值,
不难想到构图最短路径
const dx:array[..] of integer=(-,,,);
dy:array[..] of integer=(,,-,);
inf=; type link=^node;
node=record
po:longint;
len:double;
next:link;
end;
point=record
num:longint;
dis:double;
end; var num,a:array[..,..] of longint;
d:array[..] of double;
w:array[..] of link;
heap:array[..] of point;
where:array[..] of longint;
t,i,j,n,m,k,x,y:longint;
v,vn,mid:double;
p:link; procedure add(x,y:longint;c:double);
var p:link;
begin
new(p);
p^.po:=y;
p^.len:=c;
p^.next:=w[x];
w[x]:=p;
end; procedure swap(var a,b:point);
var c:point;
begin
c:=a;
a:=b;
b:=c;
end; function calc(x:longint):double;
var i:longint;
begin
calc:=;
if x> then
begin
for i:= to x do
calc:=calc*;
end
else if x< then
begin
for i:= to abs(x) do
calc:=calc/;
end;
end; procedure sift(i:longint);
var j,x,y:longint;
begin
j:=i shl ;
while j<=t do
begin
if (j+<=t) and (heap[j].dis>heap[j+].dis) then inc(j);
if heap[i].dis>heap[j].dis then
begin
x:=heap[i].num;
y:=heap[j].num;
where[x]:=j;
where[y]:=i;
swap(heap[i],heap[j]);
i:=j;
j:=i shl ;
end
else break;
end;
end; procedure up(i:longint);
var j,x,y:longint;
begin
j:=i shr ;
while j> do
begin
if heap[i].dis<heap[j].dis then
begin
x:=heap[i].num;
y:=heap[j].num;
where[x]:=j;
where[y]:=i;
swap(heap[i],heap[j]);
i:=j;
j:=j shr ;
end
else break;
end;
end; begin
readln(v,n,m);
for i:= to n do
begin
for j:= to m do
begin
read(a[i,j]);
inc(k);
num[i,j]:=k;
end;
end;
for i:= to n do
for j:= to m do
begin
vn:=v*calc(a[,]-a[i,j]);
for k:= to do
begin
x:=i+dx[k];
y:=j+dy[k];
if num[x,y]> then add(num[i,j],num[x,y],/vn);
end;
end; n:=n*m;
t:=n;
for i:= to n do
begin
if i= then d[i]:= else d[i]:=inf;
heap[i].num:=i;
heap[i].dis:=d[i];
where[i]:=i;
end;
for i:= to n do
begin
x:=heap[].num;
mid:=heap[].dis;
if mid=inf then break;
y:=heap[t].num;
where[y]:=;
swap(heap[],heap[t]);
dec(t);
sift();
p:=w[x];
while p<>nil do
begin
y:=p^.po;
if d[y]>mid+p^.len then
begin
d[y]:=mid+p^.len;
k:=where[y];
heap[k].dis:=d[y];
up(k);
end;
p:=p^.next;
end;
end;
writeln(d[n]::);
end.