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 1019. Line Painting

Why does my program get WA? (code attached)
Posted by Alex[LSD] 22 Jun 2002 12:12
{A - is the array that stores white lines, visible at the moment}

Program acm_1019; {the Line Painting}

Type Lin = Record
             L,R: longint;
           End;

Const MaxN=6000;

Var A         :array [1..maxN] of Lin;
    i,j,k,N   :longint;
    c1,c      :char;
    Cross     :array [1..MaxN] of boolean;

Function Cr(n1,n2:integer):boolean;
Begin
  cr:=(((A[n1].L>=A[n2].L)and(A[n1].L<=A[n2].R))or
       ((A[n1].R>=A[n2].L)and(A[n1].R<=A[n2].R)) )or
      (((A[n2].L>=A[n1].L)and(A[n2].L<=A[n1].R))or
       ((A[n2].R>=A[n1].L)and(A[n2].R<=A[n1].R)));
End;

Procedure NewLine(L,R:longint; C:char);
Var i,j,k,min,max     :longint;
Begin
  If c='b' then
  Begin
    For i:=1 to maxN do
    If (L>A[i].L)and(R<A[i].R) Then
                               Begin
                                 k:=1; While A[k].L>=0 do Inc(k);
                                 A[k].R:=A[i].R; A[k].L:=R;
                                 A[i].R:=L;
                               End
    Else
    Begin
      If (L<=A[i].L)and(R>=A[i].R) then Begin A[i].L:=-1; A[i].R:=-1;
End;

      If (L>A[i].L)and(L<=A[i].R) Then A[i].R:=L;
      If (R>=A[i].L)and(R<A[i].R) Then A[i].L:=R;
    End
  End
  Else
  Begin
    k:=1; While A[k].L>=0 do Inc(k);
    A[k].L:=L; A[k].R:=R; Fillchar(Cross,sizeOf(Cross),0);

    For i:=1 to maxN do
    If cr(i,k) then Begin Cross[i]:=true; End;
    min:=1000000001; max:=0;

    For i:=1 to maxN do
    Begin
      If (cross[i])and(A[i].R>max) then Max:=A[i].R;
      If (cross[i])and(A[i].L<min) then Min:=A[i].L;
    End;
    A[k].L:=min; A[k].R:=max; Cross[k]:=false;

    For i:=1 to maxN  do If cross[i] then A[i].L:=-1;
  End;
End;


Begin
   For i:=1 to 6000 do
   Begin
     A[i].L:=-1; A[i].R:=-1;
   End;
   A[1].L:=0; A[1].R:=1000000000;
   ReadLn(N);
   For i:=1 to N do
   Begin
     Read(j,k,c1,c); {c:=' ';
     While (c<>'b')or(c<>'w') do Read(c);}
     If j<k then NewLine(j,k,c);
   End;
   k:=0; j:=1;
   For i:=1 to maxN do If A[i].R-A[i].L+1>A[j].R-A[j].L+1 then j:=i;
   Writeln(A[j].L,' ',A[j].R);
End.