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

Who can help me,please?I'v got so many WAs.
Posted by wangchun 30 Jul 2004 18:45
It seems all right.But I got WA  again and again.
Who can help me with it?
type pack=array[1..2]of longint;
var sz:array[1..50000]of pack;
    n,a,b,c,t,e,l,max:longint;
    s:string;
procedure search(s_s,s_e,s_c:longint);
var t,k,move,v,add:longint;
    q:boolean;
begin
     if c=1 then
        begin
             q:=true;
             t:=1;
             repeat
                   if (s_s>=sz[t,1])and(s_s<=sz[t,2]) then
                      begin
                           q:=false;
                           move:=0;
                           k:=sz[t,2];
                           if s_e>k then
                              k:=s_e;
                           add:=t;
                           while (k>=(sz[add+1,1]))and(add<e) do
                                 begin
                                      if sz[add+1,2]>k then
                                         k:=sz[add+1,2];
                                      inc(add);
                                      inc(move);
                                 end;
                           sz[t,2]:=k;
                           if move>0 then
                              for v:=t+1 to e-move do
                                  sz[v]:=sz[v+move];
                           e:=e-move;
                           break;
                      end;
                   if (s_e>=sz[t,1])and(s_e<=sz[t,2]) then
                      begin
                           q:=false;
                           move:=0;
                           k:=sz[t,1];
                           if s_s<k then
                              k:=s_s;
                           add:=t;
                           while (k<=(sz[add-1,2]))and(add>1) do
                                 begin
                                      if sz[add-1,1]<k then
                                         k:=sz[add-1,1];
                                      dec(add);
                                      inc(move);
                                 end;
                           sz[t,1]:=k;
                           if move>0 then
                              for v:=t-move to e-move do
                                  sz[v]:=sz[v+move];
                           e:=e-move;
                           break;
                      end;
                   inc(t);
             until t>=e;
             if q then
                begin
                     for t:=1 to e-1 do
                         if (s_s>sz[t,2])and(s_e<sz[t+1,1]) then
                            begin
                                 for v:=t+2 to e+1 do
                                     sz[v]:=sz[v-1];
                                 sz[t+1,1]:=s_s;
                                 sz[t+1,2]:=s_e;
                                 inc(e);
                            end;
                     if s_s>sz[e,2] then
                        begin
                             inc(e);
                             sz[e,1]:=s_s;
                             sz[e,2]:=s_e;
                        end;
                end;
        end
            else
        begin
             for t:=1 to e do
                 begin
                      if (s_s<=sz[t,1])and(s_e>=sz[t,2]) then
                         begin
                              for v:=t to e-1 do
                                  sz[v]:=sz[v+1];
                              dec(e);
                         end
                                                         else
                         if (s_s<=sz[t,1])and(s_e>=sz[t,1]) then
                            sz[t,1]:=s_e
                                                            else
                            if (s_e>=sz[t,2])and(s_s<=sz[t,2]) then
                               sz[t,2]:=s_s
                                                              else
                               if (s_s>sz[t,1])and(s_e<sz[t,2]) then
                                  begin
                                       for v:=e+1 downto t+1 do
                                           sz[v]:=sz[v-1];
                                       inc(e);
                                       sz[t+1,2]:=sz[t,2];
                                       sz[t,2]:=s_s;
                                       sz[t+1,1]:=s_e;
                                  end;
                 end;
        end;
end;
begin
     e:=1;
     fillchar(sz,sizeof(sz),0);
     sz[1,1]:=0;
     sz[1,2]:=1000000000;
     readln(n);
     for t:=1 to n do
         begin
              read(a,b);
              readln(s);
              if pos('w',s)<>0 then
                 c:=1
                               else
                 c:=2;
              if a<b then
                 search(a,b,c);
         end;
     max:=0;
     c:=0;
     for t:=1 to e do
         begin
              l:=sz[t,2]-sz[t,1];
              if l>max then
                 begin
                      c:=t;
                      max:=l;
                 end;
         end;
     if max=0 then
        writeln(0)
              else
        writeln(sz[c,1],' ',sz[c,2]);
end.
Re: Who can help me,please?I'v got so many WAs.
Posted by Kit 23 Feb 2005 00:48
You should lay out it with indents and comments. Then, may be, someone will read it.