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 1114. Boxes

I got WA, please help give some test!
Posted by Algorithmus_UA(algorithmus@univ.kiev.ua) 12 Jun 2002 14:48
----------------------MY RROGRAM-----------------
type arr = record
             a:array[1..100]of byte;
             l:integer;
           end;
var N,a,b,i:longint;
    r,_a,_b:arr;
procedure mul_i(var a:arr;x:integer);
var c,k:longint;
    i:integer;
begin
  k:=0;
  for i:=1 to a.l do
  begin
    c:=a.a[i];
    a.a[i]:=(a.a[i]*x+k) mod 10;
    k:=(c*x+k) div 10;
  end;
  while k<>0 do
  begin
    inc(i);
    a.a[i]:=k mod 10;
    k:=k div 10;
  end;
  a.l:=i;
end;

procedure mul_i2(var a:arr;x:integer;var d:arr;p:integer);
var c,k:longint;
    i:integer;
begin
  k:=0;
  for i:=1 to a.l do
  begin
    c:=a.a[i];
    d.a[i+p]:=(a.a[i]*x+k) mod 10;
    k:=(c*x+k) div 10;
  end;
  while k<>0 do
  begin
    inc(i);
    d.a[i+p]:=k mod 10;
    k:=k div 10;
  end;
  d.l:=i+p;
end;

procedure add(var a,b:arr);
var m,i:integer;
    k,c:byte;
begin
  if a.l>b.l then m:=a.l else m:=b.l;
  k:=0;
  for i:=1 to m do
  begin
    c:=a.a[i];
    a.a[i]:=(a.a[i]+b.a[i]+k) mod 10;
    k:=(c+b.a[i]+k) div 10;
  end;
  if k = 1 then
  begin
    inc(i);
    a.a[i]:=1;
  end;
  a.l:=i;
end;

procedure mul(var a,b:arr);
var c,d:arr;
    i:integer;
begin
  d.l:=0;fillchar(d,sizeof(d),0);
  for i:=1 to a.l do
  begin
    c.l:=0;fillchar(c,sizeof(c),0);
    mul_i2(b,a.a[i],c,i-1);
    add(d,c);
  end;
  a:=d;
end;



procedure calc(a:longint;var s:arr);
var i:longint;
    x:arr;
begin
  fillchar(s,sizeof(s),0);
  fillchar(x,sizeof(x),0);
  s.l:=0;
  x.l:=1;
  x.a[1]:=1;
  for i:=0 to a do
  begin
    {s:=s+x;}add(s,x);
    {X:=X*N;}mul_i(x,N);
  end;
end;

begin
  readln(N,A,b);
  calc(a,_a);
  calc(B,_b);
  mul(_a,_b);
  for i:=_a.l downto 1 do write(_a.a[i]);
  writeln;
end.
A test for you (+)
Posted by shitty.Mishka 13 Jun 2002 12:46
The answer for this test:
2 2 2
is 36