ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1036. Lucky Tickets

Who can help me?!
Posted by Nijino Saki 3 Jun 2001 07:31
Why I received WA?

My Program in Pascal:

Program P1036;
Type TNum=Array[0..52] of Byte;
     TList=Array[1..2,0..450] of TNum;
Var A,C:TList;
    B:TNum;
    n,s,i,j,k:Integer;

Procedure Add(A:TNum; Var B:TNum);
Var p,i:Byte;
Begin
  if B[0]<A[0] then B[0]:=A[0];
  p:=0;
  for i:=1 to B[0] do
    begin
      inc(p,A[i]+B[i]);
      B[i]:=p mod 100;
      p:=p div 100
    end;
  if p<>0 then begin
                 inc(B[0]); B[B[0]]:=p
               end
End;

Procedure Out(A:TNum);
Var i:Byte;
Begin
  write(A[A[0]]);
  for i:=A[0]-1 downto 1 do
    if A[i]>=10 then write(A[i]) else write('0',A[i]);
  writeln
End;

Procedure SqrNum(B:TNum; Var C:TNum);
Var i,j:Byte;
    p:Longint;
Begin
  fillchar(C,sizeof(C),0); C[0]:=B[0]*2;
  for i:=1 to B[0] do
    if B[i]<>0 then
      begin
        p:=0;
        for j:=1 to B[0] do
          begin
            inc(p,Longint(B[i])*B[j]+C[i+j-1]);
            C[i+j-1]:=p mod 100;
            p:=p div 100
          end;
        if p<>0 then inc(C[i+B[0]],p)
      end;
  if C[C[0]]=0 then dec(C[0])
End;

Begin
  readln(n,s);
  if (s<0) or odd(s) then begin writeln(0); halt end;
  s:=s div 2;
  if s>n*9 then begin writeln(0); halt end;
  if (s=0) or (s=n*9) then begin writeln(1); halt end;
  if s=1 then begin writeln(n*n); halt end;
  fillchar(A[1],sizeof(A[1]),0);
  for i:=0 to 9 do begin A[1,i,1]:=1; A[1,i,0]:=1 end;
  for i:=2 to n do
    begin
      fillchar(A[2],sizeof(A[2]),0);
      for j:=0 to 9 do
        for k:=0 to 9*i-9 do
          if j+k<=s then Add(A[1,k],A[2,j+k]);
      A[1]:=A[2]
    end;
  SqrNum(A[2,s],B);
  Out(B)
End.
I wonder, why you don't get a compilation error.
Posted by Deian Lambov 30 Nov 2001 09:25
The "add" procedure is obviously wrong.
the "p" variable there is not initialized.
"i" is never used.
And what the hell "b[0]0" does mean? May be "b[0]=0"?


> Why I received WA?
>
> My Program in Pascal:
>
> Program P1036;
> Type TNum=Array[0..52] of Byte;
>      TList=Array[1..2,0..450] of TNum;
> Var A,C:TList;
>     B:TNum;
>     n,s,i,j,k:Integer;
>
> Procedure Add(A:TNum; Var B:TNum);
> Var p,i:Byte;
> Begin
>   if B[0]<A[0] then B[0]:=A[0];
>   p:=0;
>   for i:=1 to B[0] do
>     begin
>       inc(p,A[i]+B[i]);
>       B[i]:=p mod 100;
>       p:=p div 100
>     end;
>   if p<>0 then begin
>                  inc(B[0]); B[B[0]]:=p
>                end
> End;
>
> Procedure Out(A:TNum);
> Var i:Byte;
> Begin
>   write(A[A[0]]);
>   for i:=A[0]-1 downto 1 do
>     if A[i]>=10 then write(A[i]) else write('0',A[i]);
>   writeln
> End;
>
> Procedure SqrNum(B:TNum; Var C:TNum);
> Var i,j:Byte;
>     p:Longint;
> Begin
>   fillchar(C,sizeof(C),0); C[0]:=B[0]*2;
>   for i:=1 to B[0] do
>     if B[i]<>0 then
>       begin
>         p:=0;
>         for j:=1 to B[0] do
>           begin
>             inc(p,Longint(B[i])*B[j]+C[i+j-1]);
>             C[i+j-1]:=p mod 100;
>             p:=p div 100
>           end;
>         if p<>0 then inc(C[i+B[0]],p)
>       end;
>   if C[C[0]]=0 then dec(C[0])
> End;
>
> Begin
>   readln(n,s);
>   if (s<0) or odd(s) then begin writeln(0); halt end;
>   s:=s div 2;
>   if s>n*9 then begin writeln(0); halt end;
>   if (s=0) or (s=n*9) then begin writeln(1); halt end;
>   if s=1 then begin writeln(n*n); halt end;
>   fillchar(A[1],sizeof(A[1]),0);
>   for i:=0 to 9 do begin A[1,i,1]:=1; A[1,i,0]:=1 end;
>   for i:=2 to n do
>     begin
>       fillchar(A[2],sizeof(A[2]),0);
>       for j:=0 to 9 do
>         for k:=0 to 9*i-9 do
>           if j+k<=s then Add(A[1,k],A[2,j+k]);
>       A[1]:=A[2]
>     end;
>   SqrNum(A[2,s],B);
>   Out(B)
> End.
>
>