LSTTCD2 - Thử thách cực đại - Đá chìm đá nổi 2

Tác giả: RR

Ngôn ngữ: Pascal

{$MODE OBJFPC}

uses math;
const
  FINP          =       '';
  FOUT          =       '';
  MAXN          =       10111;
  debug         =       false;

var
  f1,f2         :       text;
  n,now,x,y     :       longint;

procedure openF;
    begin
      assign(f1,FINP); reset(f1);
      assign(f2,FOUT); rewrite(f2);
    end;

procedure closeF;
    begin
      close(f1);
      close(f2);
    end;

procedure l2;
    begin
      write(f2,'L 2');
      dec(now,2);
      if debug then writeln(f2,'   ',now) else writeln(f2);
    end;

procedure r2;
    begin
      write(f2,'R 2');
      inc(now,2);
      if debug then writeln(f2,'   ',now) else writeln(f2);
    end;

procedure l1;
    begin
      write(f2,'L 1');
      dec(now);
      if debug then writeln(f2,'   ',now) else writeln(f2);
    end;

procedure r1;
    begin
      write(f2,'R 1');
      inc(now);
      if debug then writeln(f2,'   ',now) else writeln(f2);
    end;

procedure xuoi;
    begin
      now:=x;
      if (y=x+1) and (x<>1) and (y<>n) then begin writeln(f2,-1); exit; end;
      while (now>2) do l2;
      if (now=1) and (y=2) then r2
      else if now=1 then r1 else l1;
      while (now<x+1) do r2;
      while (now<y-1) do r1;
      while (now<=n-2) and (y<n) do r2;
      if (now=n) and (now<>y) then l1 else if now<>y then r1;
      while now<>y do l2;
      writeln(f2,'WIN');
    end;

procedure nguoc;
    begin
      now:=x;
      if (x=y+1) and (y<>1) and (x<>n) then begin writeln(f2,-1); exit; end;
      while (now<=n-2) do r2;
      if (now=n) and (y=n-1) then l2
      else if now=n then l1 else r1;
      while (now>x-1) do l2;
      while (now>y+1) do l1;
      while (now>2) and (y>1) do l2;
      if (now=1) and (now<>y) then r1 else if now<>y then l1;
      while now<>y do r2;
      writeln(f2,'WIN');
    end;

procedure solve2;
    begin
      if x<y then r1 else l1;
      writeln(f2,'WIN');
    end;

begin
  openF;
  read(f1,n,x,y);
  if n=1 then writeln(f2,'WIN')
  else if x=y then writeln(f2,-1)
  else if n=2 then solve2
  else if x<y then xuoi
  else nguoc;
  closeF;
end.

Download