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

Help !!! PLEASE !!! What's wrong in my code ?????????
Posted by Romanchik Vitaly 21 Aug 2002 16:25
const nmax=100;
type mas=array[1..nmax]of longint;
var aa:array[0..500]of mas;
    i:longint;
    s:longint;
    n:longint;
    m,j:longint;
    a,b,c:mas;
function dlina(a:mas):longint;
var i:longint;
begin
 i:=nmax;
 while a[i]=0 do dec(i);
 dlina:=i;
end;
procedure slog(a,b:mas;var c:mas);
var i,d1,d2,max:longint;
begin
 fillchar(c,sizeof(c),0);
 d1:=dlina(a);d2:=dlina(b);
 if d1>d2 then max:=d1 else max:=d2;
 for i:=1 to max do
  begin
   c[i]:=c[i]+a[i]+b[i];
   if c[i]>9 then
    begin
     c[i+1]:=c[i] div 10;
     c[i]:=c[i] mod 10;
    end;
  end;
end;
procedure umn(a:mas;var c:mas);
var i,j,p,z,d:longint;
begin
 d:=dlina(a);
 fillchar(c,sizeof(c),0);
 for i:=1 to d do
  begin
   p:=0;
   for j:=1 to d do
    begin
     z:=a[i]*a[j]+p+c[i+j-1];
     c[i+j-1]:=z mod 10;
     p:=z div 10;
    end;
   c[i+j]:=p;
  end;
end;
begin
 readln(n,s);
 if (s div 2>n*9)or(odd(n)) then
  begin
   writeln(0);
   halt;
  end;
 if n=1 then
  begin
   if s>9 then
    writeln(0)else writeln(1);
    halt;
  end;
 s:=s div 2;
 aa[0][1]:=1;
 for i:=1 to n do
  begin
  if s>9*i then m:=0 else m:=s;
   for j:=1 to m do
    begin
    slog(aa[j-1],aa[j],c);
    aa[j]:=c;
    end;
  end;
 umn(aa[m],c);
 for i:=dlina(c)downto 1 do
  write(c[i]);
 writeln;
end.