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? I always get WA!
Posted by Bighead 20 Apr 2002 12:54
  Though I think my program is correct, the judger always give me WA,
why?
  Here is my code. I use a longint to save 4 digits:

program U1036;
const
  digits=10000;
type
  bignum=array[1..80] of longint;
var
  f:array[1..2,0..1000] of bignum;
  n,s,i,j,k,l:longint;
  re:array[1..400] of longint;
  ns:string;

  procedure add(p,q:longint);
  var
    i,j:longint;
  begin
    for i:=1 to 80 do begin
      inc(f[2,p,i],f[1,q,i]);
      if f[2,p,i]>digits then begin
        inc(f[2,p,i+1]);
        dec(f[2,p,i],digits);
      end;
    end;
  end;

begin
  readln(n,s);
  if n=0 then begin
    writeln(0);
    halt;
  end;
  fillchar(f,sizeof(F),0);
  for i:=0 to 9 do f[1,i,1]:=1;
  if (n*9*2<s)or odd(s) then begin
    writeln(0);
    halt;
  end;
  s:=s div 2;
  fillchar(f[2],sizeof(f[2]),0);
  for i:=2 to n do begin
    if 9*i>s then l:=s else l:=9*i;
    for j:=0 to 9*i do
      for k:=0 to 9 do
        add(j+k,j);
    if i<>n then begin
      f[1]:=f[2];
      fillchar(f[2],sizeof(f[2]),0);
    end;
  end;
  fillchar(re,sizeof(re),0);
  for i:=1 to 80 do
    for j:=1 to 80 do
      inc(re[i+j-1],f[2,s,i]*f[2,s,j]);
  for i:=1 to 400 do
    if re[i]>digits then begin
      inc(re[i+1],re[i] div digits);
      re[i]:=re[i] mod digits;
    end;
  i:=400;
  while (re[i]=0)and(i>0) do dec(i);
  if i=0 then writeln(0) else begin
    write(re[i]);
    for j:=i-1 downto 1 do begin
      str(re[j],ns);
      while length(ns)<4 do ns:='0'+ns;
      write(ns);
    end;
    writeln;
  end;
end.