测评机: Xeond[6]
得分: 40分
提交日期: 2010-7-1 15:27:00
有效耗时: 812毫秒
测试结果1: 通过本测试点|有效耗时187ms
测试结果2: 通过本测试点|有效耗时47ms
测试结果3: 测试结果错误.错误结果为:-1
正确结果应为:171
测试结果4: 通过本测试点|有效耗时218ms
测试结果5: 通过本测试点|有效耗时360ms
测试结果6: 测试结果错误.错误结果为:-1
正确结果应为:38
测试结果7: 测试结果错误.错误结果为:-1
正确结果应为:80
测试结果8: 测试结果错误.错误结果为:-1
正确结果应为:116
测试结果9: 测试结果错误.错误结果为:-1
正确结果应为:128
测试结果10: 测试结果错误.错误结果为:58
正确结果应为:55
提交代码:
program ex01;
var
i,j,m,x,y,maxx,maxy,num,ans,now:longint;
t,f:array[-1..402,-1..402] of longint;
xx,yy:array[0..200000] of longint;
begin
assign(input,'in.txt');
reset(input);
readln(m);
for i:=1 to m do
begin
read(x,y);
if (maxx<x) then maxx:=x;
if (maxy<y) then maxy:=y;
readln(now);
if (now<t[x,y]) or (t[x,y]=0) then t[x,y]:=now;
if (t[x-1,y]=0) or (t[x-1,y]>now) then t[x-1,y]:=now;
if (t[x+1,y]=0) or (t[x+1,y]>now) then t[x+1,y]:=now;
if (t[x,y-1]=0) or (t[x,y-1]>now) then t[x,y-1]:=now;
if (t[x,y+1]=0) or (t[x,y+1]>now) then t[x,y+1]:=now;
end;
for i:=0 to maxx+1 do
for j:=0 to maxy+1 do
if (t[i,j]=0)
then begin
inc(num);
xx[num]:=i;yy[num]:=j;
t[i,j]:=maxlongint;
end;
for i:=0 to maxx+1 do
for j:=0 to maxy+1 do
begin
if (i<>0) or (j<>0) then begin
if (i>=1) and (j>=1)
then if (f[i-1,j]<f[i,j-1]) then f[i,j]:=f[i-1,j]
else f[i,j]:=f[i,j-1];
if (i>=1) and (j=0) then f[i,j]:=f[i-1,j];
if (i=0) and (j>=1) then f[i,j]:=f[i,j-1];
if (f[i,j]<>maxlongint)
then if (f[i,j]<t[i,j]-1)
then inc(f[i,j])
else f[i,j]:=maxlongint;
end;
end;
ans:=maxlongint;
for i:=1 to num do
if (ans>f[xx[i],yy[i]])
then ans:=f[xx[i],yy[i]];
if (ans<>maxlongint) or ((x=0) and (y=0))
then writeln(ans)
else writeln('-1');
end.