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

I can pass test 1
Posted by hailoc12 28 Sep 2006 15:31
{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R+,S+,T-,V+,X+,Y+}
{$M 16384,0,655360}
Const Maxn= 20;
      dx  : Array[1..4] Of Integer =( 1,0,-1, 0);
      dy  : Array[1..4] Of Integer =( 0,1, 0,-1);
      Nb  : Array[1..4] Of Char    =('R','T','L','B');

Var Matrix: Array[0..Maxn+1, 0..Maxn+1] Of Boolean;
    n: Integer;
    i, j, t: Integer;
    minx, miny: Integer;
Procedure Print2;
  Var Queuex, Queuey: Array[1..Maxn*Maxn] Of Integer;
      Front, Rear: Integer;
      x, y, count, i: Integer;
      ch: Char;
      st: String;
  Begin
      FillChar(Matrix, SizeOf(Matrix), False);
      Queuex[1]:= minx; Queuey[1]:= miny; Front:= 1; Rear:= 1;
      Matrix[minx, miny]:= True;
      count:= 1;
      While Rear<= Front Do
        Begin
          x:= Queuex[Rear]; y:= Queuey[Rear]; Inc(Rear);
          Readln(st);
          i:= 1;
          While st[i]<>',' Do
            Begin
              Case upcase(st[i]) Of
                'R':Begin Inc(Front); Queuex[Front]:= x+ dx[1];
                          Queuey[Front]:= y+ dy[1];
                          Matrix[x+dx[1], y+dy[1]]:= True;
                          inc(Count);
                    End;
                'T':Begin Inc(Front); Queuex[Front]:= x+ dx[2];
                          Queuey[Front]:= y+ dy[2];
                          Matrix[x+dx[2], y+dy[2]]:= True;
                          inc(Count);
                    End;
                'L':Begin Inc(Front); Queuex[Front]:= x+ dx[3];
                          Queuey[Front]:= y+ dy[3];
                          Matrix[x+dx[3], y+dy[3]]:= True;
                          inc(Count);
                    End;
                'B':Begin Inc(Front); Queuex[Front]:= x+ dx[4];
                          Queuey[Front]:= y+ dy[4];
                          Matrix[x+dx[4], y+dy[4]]:= True;
                          inc(Count);
                    End;
                '.': Break;
              End;
              inc(i);
            End;
        End;
      Writeln(Count);
      For x:= 1 To Maxn Do
        For y:= 1 To Maxn Do
          If Matrix[x, y] Then Writeln(x,' ', y);
  End;
Procedure Print1;
  Var Queuex, Queuey: Array[1..Maxn*Maxn] Of Integer;
      x, y, k: Integer;
      Front, Rear: Integer;
      first: Boolean;
  Begin
      Writeln(minx, ' ', miny);
      Queuex[1]:= minx; Queuey[1]:= miny;
      Front:= 1; Rear:= 1;
      Matrix[minx, miny]:= False;
      First:= True;
      While Rear<= Front Do
       Begin
        If Not First Then Writeln(',')
        Else First:= False;
        x:= Queuex[Rear]; y:= Queuey[Rear]; Inc(Rear);
        For k:=1 To 4 Do
          If Matrix[x+dx[k], y+dy[k]] Then
            Begin
              Write(Nb[k]);
              Matrix[x+dx[k], y+dy[k]]:= False;
              Inc(Front); Queuex[Front]:= x+dx[k]; Queuey[Front]:= y+ dy[k]
            End;

       End;
      Writeln('.');
  End;
Var st: string;
Begin
  st:='';
  Read(n);
  If Eoln Then
    Begin
       FillChar(Matrix, SizeOf(Matrix), False);
       minx:= Maxint; miny:= minx;
       For i:=1 To n Do
         Begin
           Readln(j, t);
           If (j= Minx) And (t< Miny) Then Miny:= t;
           If (j< Minx) ANd (t= Miny) Then Minx:= j;
           If (j< Minx) And (t< Miny) Then Begin minx:= j; miny:= t; End;
           Matrix[j, t]:= True;
         End;
       Print1;
    End
  Else
    Begin
      minx:= n;
      Readln(miny);
      Print2;
    End;
End.

I tried with many test, It all returned the true answer but not to be accepted.
Re: I can pass test 1
Posted by AlexF 28 Sep 2006 15:41
Delete this
{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R+,S+,T-,V+,X+,Y+}
{$M 16384,0,655360}
And you'll get AC!
Thank you alots
Posted by hailoc12 28 Sep 2006 19:46
I have got AC.
I have repaired it for all today'afternoon but found nothing.
Can you explain to me why my program got wrong with some directive compilers, It should be warned in FAQ.
Re: Thank you alots
Posted by AlexF 28 Sep 2006 20:25
In my timus programs I've never used any directive compilers, except {$M 16777216}, so in this question I can't help you! ))
Re: Thank you alots
Posted by KIRILL 28 Sep 2006 22:52
Because of you use
{$M 16384,0,655360} directive
which have the next syntax:
{$M minstacksize,maxstacksize}
or
{$M reservedbytes} for Linux