记录编号 |
7626 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[BYVoid S1] 血色叛徒 |
最终得分 |
100 |
用户昵称 |
E.M.B.E.R |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.496 s |
提交时间 |
2008-11-10 20:33:56 |
内存使用 |
19.19 MiB |
显示代码纯文本
program EmberAsh;
var
f:array[0..1000,0..1000]of longint;//矩阵
bx,by:array[1..1000000]of longint;//领主
ax,ay:array[1..1000000]of longint;//感染源
i,j,k,m,n,a,b,vv,time,x,y,a1,head,tail:longint;
fin,fout:text;
BEGIN
assign(fin,'crusade.in');reset(fin);
assign(fout,'crusade.out');rewrite(fout);
readln(fin,n,m,a,b);
for i:=0 to n do
for j:=0 to m do
f[i,j]:=-1;//初始化
for i:=1 to a do
begin
readln(fin,ax[i],ay[i]);
f[ax[i],ay[i]]:=0;//感染源
end;
vv:=0;//矩阵被感染人数为a
for i:=1 to b do
begin
readln(fin,bx[i],by[i]);
if f[bx[i],by[i]]=0 then
inc(vv)
else
f[bx[i],by[i]]:=-3;//领主
end;
time:=0;
head:=1;tail:=a;
while vv<b do
begin
inc(time);
a1:=a;
for i:=head to a do
begin
x:=ax[i];y:=ay[i];
if ((f[x,y+1]=-1)or(f[x,y+1]=-3))and(y+1<=m) then
begin
if f[x,y+1]=-3 then inc(vv);
f[x,y+1]:=time;
inc(a);
ax[a]:=x;ay[a]:=y+1;
end;//1
if ((f[x+1,y]=-1)or(f[x+1,y]=-3))and(x+1<=n) then
begin
if f[x+1,y]=-3 then inc(vv);
f[x+1,y]:=time;
inc(a);
ax[a]:=x+1;ay[a]:=y;
end;//2
if ((f[x,y-1]=-1)or(f[x,y-1]=-3))and(y-1>0) then
begin
if f[x,y-1]=-3 then inc(vv);
f[x,y-1]:=time;
inc(a);
ax[a]:=x;ay[a]:=y-1;
end;//3
if ((f[x-1,y]=-1)or(f[x-1,y]=-3))and(x-1>0) then
begin
if f[x-1,y]=-3 then inc(vv);
f[x-1,y]:=time;
inc(a);
ax[a]:=x-1;ay[a]:=y;
end;//4
end;
head:=a1;
end;//while
for i:=1 to b do
writeln(fout,f[bx[i],by[i]]);
close(fin);close(fout);
END.