Why my AC 1012 program WA at 1013
I made my array 10000, but still WA.
type
arr=array [1..10000] of byte;
var
p1,p2,p3,p4:arr;
i,j,k,n,pos1,pos2,pos3,pos4:integer;
procedure init;
begin
read(n,k);
p2[1]:=1;
p3[1]:=k-1;
pos2:=1;
pos3:=1;
end;
procedure plus(p1,p2:arr);
var i:integer;
begin
fillchar(p4,sizeof(p4),0);
for i:=1 to pos2 do
begin
inc(p4[i],p1[i]+p2[i]);
if p4[i]>=10
then begin
inc(p4[i+1],p4[i] div 10);
p4[i]:=p4[i] mod 10;
end;
end;
if pos1=pos2
then begin
if p4[pos2+1]>0 then pos4:=pos2+1
else pos4:=pos2;
end
else pos4:=pos2;
end;
procedure multiply(m:integer;p4:arr);
var i:integer;
judge:boolean;
begin
fillchar(p3,sizeof(p3),0);
for i:=1 to pos4 do
begin
inc(p3[i],m*p4[i]);
if p3[i]>=10
then begin
inc(p3[i+1],p3[i] div 10);
p3[i]:=p3[i] mod 10;
end;
end;
inc(i); judge:=true;
while p3[i]>=10 do
begin
inc(p3[i+1],p3[i] div 10);
p3[i]:=p3[i] mod 10;
inc(i); judge:=false;
end;
if (judge)and(p3[i]=0) then pos3:=i-1
else pos3:=i;
end;
begin
init;
for i:=2 to n do
begin
p1:=p2; p2:=p3;
pos1:=pos2; pos2:=pos3;
plus(p1,p2);
multiply(k-1,p4);
end;
for i:=pos3 downto 1 do
write(p3[i]);
writeln;
end.