why does my program get "WA"?!?!
Const
InFile = 'p1251.in';
OutFile = 'p1251.out';
Limit = 100;
LimitNew = 10000;
LimitQueue = 30000;
Mask = 1 shl 9 - 1;
dirx : array[1..8] of longint = (-1 , -1 , -1 , 0 , 0 , 1 ,
1 , 1);
diry : array[1..8] of longint = (-1 , 0 , 1 , -1 , 1 , -1 ,
0 , 1);
Type
Tdata = array[1..Limit , 1..Limit] of
record
covered ,
lastvisit : longint;
end;
Tindex = array[1..LimitNew] of
record
x , y : longint;
end;
Tsum = array[1..Limit] of longint;
Tkey = record
time , x , y , sign , p : longint;
end;
Tqueue = array[1..LimitQueue] of Tkey;
Var
data : Tdata;
sum : Tsum;
index : Tindex;
queue : Tqueue;
N , M ,
total , ans ,
number : longint;
procedure init;
var
i : longint;
begin
readln(N , M);
fillchar(data , sizeof(data) , 0);
fillchar(queue , sizeof(queue) , 0);
fillchar(index , sizeof(index) , 0);
for i := 1 to N do sum[i] := M;
total := 0;
end;
procedure find_pos(var x , y : longint);
begin
x := 1;
while (x <= N) and (sum[x] = 0) do inc(x);
if x > N then
x := 0
else
begin
y := 1;
while data[x , y].covered <> 0 do inc(y);
end;
end;
procedure process;
var
dir ,
nx , ny , p ,
newp : longint;
key : Tkey;
begin
if queue[1].sign = 1 then
if data[queue[1].x , queue[1].y].lastvisit < queue[1].time -
1000 then
begin
index[queue[1].p].x := 0; index[queue[1].p].y := 0;
if odd(data[queue[1].x , queue[1].y].covered) then
begin
dec(data[queue[1].x , queue[1].y].covered);
if data[queue[1].x , queue[1].y].covered = 0 then
inc(sum[queue[1].x]);
end;
end;
if queue[1].sign = 2 then
if data[queue[1].x , queue[1].y].lastvisit < queue[1].time -
100 then
begin
for dir := 1 to 8 do
begin
nx := queue[1].x + dirx[dir]; ny := queue[1].y +
diry[dir];
if (nx >= 1) and (ny >= 1) and (nx <= N) and (ny <=
M) then
begin
p := data[nx , ny].covered;
data[nx , ny].covered := data[nx ,
ny].covered and (Mask - 1 shl dir);
if (p <> 0) and (data[nx , ny].covered = 0)
then inc(sum[nx]);
end;
end;
end;
dec(total);
if total <> 0 then
begin
key := queue[total + 1]; p := 1;
while p * 2 <= total do
begin
newp := p;
if queue[p * 2].time < key.time then newp := p * 2;
if (p * 2 < total) and (queue[p * 2 + 1].time <
key.time) and (queue[p * 2 + 1].time < queue[p * 2].time) then
newp := p * 2 + 1;
if newp = p then break;
queue[p] := queue[newp];
p := newp;
end;
queue[p] := key;
end;
end;
procedure shift(p : longint);
var
key : Tkey;
begin
p := total; key := queue[p];
while p <> 1 do
if queue[p div 2].time > key.time then
begin
queue[p] := queue[p div 2];
p := p div 2;
end
else
break;
queue[p] := key;
end;
procedure add(time , x , y , num : longint);
var
dir ,
nx , ny : longint;
begin
data[x , y]