SETNJA - Setnja

Tác giả: RR

Ngôn ngữ: Pascal

//Written by RR
{$ifdef rr}
  {$r+,q+}
  {$mode objfpc}
  {$inline off}
{$else}
  {$r-,q-}
  {$mode objfpc}
  {$inline on}
{$endif}

uses math;
const
  FINP          =       '';
  FOUT          =       '';
  scs           =       400;
  base          =       1000000000000000000;
  lbase         =       18;
type
  big           =       array[0..scs] of qword;
var
  f1,f2         :       text;
  s             :       ansistring;
  n             :       longint;
  skn,val       :       big;

procedure openF;
    begin
      assign(f1,FINP); reset(f1);
      assign(f2,FOUT); rewrite(f2);
    end;
procedure closeF;
    begin
      close(f1);
      close(f2);
    end;
procedure inp;
    begin
      readln(f1,s);
      n:=length(s);
    end;
procedure mul2(var a:big); inline;
    var
      i,nho:longint;
    begin
      nho:=0;
      for i:=1 to a[0] do
        begin
          a[i]:=a[i]<<1+nho;
          if a[i]<base then nho:=0
          else begin nho:=1; dec(a[i],base); end;
        end;
      if nho>0 then
        begin
          inc(a[0]);
          a[a[0]]:=nho;
        end;
    end;
procedure add(var a,b:big); inline;
    var
      i,nho:longint;
    begin
      nho:=0;
      if b[0]>a[0] then a[0]:=b[0];
      for i:=1 to a[0] do
        begin
          a[i]:=a[i]+b[i]+nho;
          if a[i]<base then nho:=0
          else begin nho:=1; dec(a[i],base); end;
        end;
      if nho>0 then
        begin
          inc(a[0]);
          a[a[0]]:=nho;
        end;
    end;
procedure mul3(var a:big); inline;
    var
      i,nho:longint;
    begin
      nho:=0;
      for i:=1 to a[0] do
        begin
          a[i]:=a[i]<<1+a[i]+nho;
          if a[i]<base then nho:=0
          else begin nho:=a[i] div base; a[i]:=a[i] mod base; end;
        end;
      if nho>0 then
        begin
          inc(a[0]);
          a[a[0]]:=nho;
        end;
    end;
procedure mul5(var a:big); inline;
    var
      i,nho:longint;
    begin
      nho:=0;
      for i:=1 to a[0] do
        begin
          a[i]:=a[i]<<2+a[i]+nho;
          if a[i]<base then nho:=0
          else begin nho:=a[i] div base; a[i]:=a[i] mod base; end;
        end;
      if nho>0 then
        begin
          inc(a[0]);
          a[a[0]]:=nho;
        end;
    end;
procedure solve;
    var
      i:longint;
    begin
      skn[0]:=1; skn[1]:=1;
      val[0]:=1; val[1]:=1;
      for i:=1 to n do
        case s[i] of
          'L': mul2(val);
          'R': begin mul2(val); add(val,skn); end;
          '*': begin mul5(val); add(val,skn); mul3(skn); end;
        end;
    end;
procedure print(var a:big);
    var
      s:string[20];
      i:longint;
    begin
      write(f2,a[a[0]]);
      for i:=a[0]-1 downto 1 do
        begin
          str(a[i],s);
          while length(s)<lbase do s:='0'+s;
          write(f2,s);
        end;
      writeln(f2);
    end;

begin
  openF;
  inp;
  solve;
  print(val);
  closeF;
end.

Download