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 1008. Image Encoding

Why I got WA ??!
Posted by Dejan Kolundzija 30 Nov 2001 14:48
I made my program for first and second case but i still got
WA. Is the INPUT sample correct?
--
Faith & Respect,
Dejan

p.s. I left my SOURCE -->>>

program Problem_1008_Image_encoding ;

  const
      WHITE        =    0 ;
    BLACK        =    1 ;
    WATCHED    =    2 ;

    RIGHT        =    1 ;
    BOTTOM    =    2 ;
    LEFT        =    3 ;
    TOP            =    4 ;

    Watch        :    array [1 .. 4] of Char =
('R','B','L','T') ;

    maxX        =    11 ;
    maxN        =    101 ;

    var
      N    :    Integer ;
    Pix : array [1 .. maxX , 1 .. maxX] of Byte ;

    q        :    array [1 .. maxX * maxX] of record
x , y : Integer ; end ;
    h,    t    :    Integer ;

    line    :    array [1 .. maxN] of string [10] ;

    Stored    :    Integer ;
    Store    :    array [1 .. maxN] of record x, y :
Byte ; end ;

    EyeTo    :    array ['A' .. 'Z'] of Byte ;


      procedure init_Queue ;
        begin h := 1 ; t := 1 ; end ;

    procedure EnQueue(x , y : Integer) ;
        begin q [t].x := x ; q [t].y := y ; Inc(t) ; end ;

    procedure DeQueue(var x , y : Integer) ;
        begin x := q [h].x ; y := q [h].y ; Inc(h) ; end ;


    function Look(px , py : Integer ; var nx , ny :
Integer ; Eye : Byte) : Boolean ;
      begin
          nx := px ; ny := py ;
          case Eye of
            RIGHT        :    Inc(nx) ;
          BOTTOM    :    Dec(ny) ;
          LEFT        :    Dec(nx) ;
          TOP            :    Inc(ny) ;
        end ;
        Look := (nx > 0) and (nx < 11) and (ny > 0) and (ny
< 11) ;
      end ;


    function Mode(s : string; var a, b : Integer) :
Boolean ;
      var
          i    :    Integer ;
        begin
          a := 0 ; b := 0 ;

                i := 1 ;
                while i <= Length(s) do
            if not (s [i] in ['0' .. '9']) then
              BREAK
          else
              begin

    a := 10 * a + Ord(s [i]) - Ord('0') ;
              Inc(i) ;
            end ;
        Inc(i) ;
        while i <= Length(s) do
            if not (s [i] in ['0' .. '9']) then
              BREAK
          else
              begin

    b := 10 * b + Ord(s [i]) - Ord('0') ;
              Inc(i) ;
            end ;

        Mode := (b = 0) and (s <> '.') ;
      end ;


    procedure SwapInt(var a, b : Byte) ;
        var    c    :    Byte ;
      begin c := a ; a := b ; b := c ; end ;


    procedure Swap(i, j : Integer) ;
        begin
          SwapInt(Store [i].X, Store [j].X) ;
        SwapInt(Store [i].Y, Store [j].Y) ;
      end ;


    procedure Sort ;
        var    i    ,    j    :    Integer ;
      begin
          for i := 1 to N - 1 do
            for j := i + 1 to N do
                        if (Store
[i].X > Store [j].X) or
                 ((Store [i].X = Store [j].X) and (Store
[i].Y > Store [j].Y)) then
                   Swap(i, j) ;
      end ;


  var
      x,    y,    i,    w    :    Integer ;
    lx,    ly,    tx,    ty,    nx,    ny    :
    Integer ;
    Eye    :    Byte ;

    s    :    string ;
    A,    B    :    Integer ;

    f    :    Text ;

  begin
{      Assign(Input , 'input.txt') ; Reset(Input) ;
    Assign(Output , 'output.txt') ; ReWrite(Output) ;}

      ReadLn(s) ;

    if Mode(s, A, B) then
        begin
          N := A ;
          if N = 0 then
                    begin
                        Write('.') ;
                        EXIT ;
          end ;

            FillChar(Pix , SizeOf(Pix) , WHITE) ;
            for i := 1 to N do
                begin
                        Read(x ,
y) ;
                if i = 1 then begin lx := x ; ly :=
y ; end ;
                Pix [y , x] := BLACK ;
              end ;

            WriteLn(lx , ' ' , ly) ; Pix [ly ,
lx] := WATCHED ;
            init_Queue ;
            EnQueue(lx , ly) ;
            while h <> t do
                    begin
                        DeQueue
(tx , ty) ; Dec(N) ;
                        for Eye :=
RIGHT to TOP do
                            if
Look(tx , ty , nx , ny , Eye) then

    if Pix [ny , nx] = BLACK then

        begin
                          EnQueue(nx , ny) ;
                        Pix [ny , nx] := WATCHED ;
                        Write(Watch [Eye]) ;
                      end ;

                if h <> t then WriteLn(',')
            else Write('.') ;