why am i got WA.here is my program.Please help me find the error.Please!!!!!!!!!! type repaint =^node; node =record a,b:longint; c:char; next:repaint end; var line :repaint; n,i,code :integer; a,b :longint; c :char; s,s1,s2 :string; Procedure work; var p1,p2,p3 :repaint; bool1,bool2 :boolean; p :integer; begin p1:=line; if p1^.next=nil then if c='w' then exit else begin new(p2); p2^.next:=nil; p2^.a:=b; p2^.b:=p1^.b; p1^.b:=a; p1^.next:=p2; end; bool1:=true; while p1<>nil do begin if (a>=p1^.a) and (p1^.b>a) then break; if p1^.next<>nil then if (p1^.b<=a) and (p1^.next^.a>a) then begin bool1:=false; break; end; p1:=p1^.next; end; p2:=line; bool2:=true; while p2<>nil do begin if (b>p2^.a) and (b<=p2^.b) then break; if p2^.next<>nil then if (b>p2^.b) and (p2^.next^.a>=b) then begin bool2:=false; break; end; p2:=p2^.next; end; if c='w' then begin if bool1 and bool2 then begin p1^.b:=p2^.b; p1^.next:=p2^.next; end; if not(bool1) and not(bool2) then begin new(p3); p3^.a:=a; p3^.b:=b; p3^.next:=p2^.next; p1^.next:=p3; end; if not(bool1) and bool2 then begin p1^.next:=p2; p2^.a:=a; end; if bool1 and not(bool2) then begin p1^.next:=p2^.next; p1^.b:=b; end; end else begin if bool1 and bool2 then begin new(p3); p3^.next:=p2^.next; p3^.b:=p2^.b; p3^.a:=b; p1^.b:=a; p1^.next:=p3; end; if not(bool1) and not(bool2) then begin p1^.next:=p2^.next; end; if not(bool1) and bool2 then begin p2^.a:=b; p1^.next:=p2; end; if bool1 and not(bool2) then begin p1^.b:=a; p1^.next:=p2^.next; end; end; p:=4; while (p1^.next<>nil) and (p>0) do begin if p1^.b=p1^.next^.a then begin p1^.b:=p1^.next^.b; p1^.next:=p1^.next^.next; end; p1:=p1^.next; dec(p); end end; Procedure out; var p1 :repaint; maxx,maxy :LONGINT; begin maxx:=line^.a; maxy:=line^.b; p1:=line^.next; while p1<>nil do begin if (p1^.b-p1^.a)>(maxy-maxx) then begin maxx:=p1^.a; maxy:=p1^.b; end; p1:=p1^.next; end; writeln(maxx,' ',maxy); end; begin readln(n); new(line); line^.a:=0; line^.b:=4000; line^.next:=nil; for i:=1 to n do begin readln(s); s1:=copy(s,1,pos(' ',s)-1); delete(s,1,pos(' ',s)); val(s1,a,code); s2:=copy(s,1,pos(' ',s)-1); val(s2,b,code); if pos('b',s)<>0 then c:='b' else c:='w'; work; end; out; end. i'm sorry. i made a mistake. why am i got TLE. when it run on my own computer, it's Okay. here is my program.Please help me find the error.Please!!!!!!!!!! > type > repaint =^node; > node =record a,b:longint; c:char; next:repaint end; > var > line :repaint; > n,i,code :integer; > a,b :longint; > c :char; > s,s1,s2 :string; > > Procedure work; > var > p1,p2,p3 :repaint; > bool1,bool2 :boolean; > p :integer; > begin > p1:=line; > if p1^.next=nil then > if c='w' then exit else begin new(p2); p2^.next:=nil; p2^.a:=b; > p2^.b:=p1^.b; p1^.b:=a; p1^.next:=p2; end; > bool1:=true; > while p1<>nil do > begin > if (a>=p1^.a) and (p1^.b>a) then break; > if p1^.next<>nil then if (p1^.b<=a) and (p1^.next^.a>a) then > begin bool1:=false; break; end; > p1:=p1^.next; > end; > p2:=line; > bool2:=true; > while p2<>nil do > begin > if (b>p2^.a) and (b<=p2^.b) then break; > if p2^.next<>nil then if (b>p2^.b) and (p2^.next^.a>=b) then > begin bool2:=false; break; end; > p2:=p2^.next; > end; > if c='w' then > begin > if bool1 and bool2 then begin p1^.b:=p2^.b; > p1^.next:=p2^.next; end; > if not(bool1) and not(bool2) then begin new(p3); p3^.a:=a; > p3^.b:=b; p3^.next:=p2^.next; p1^.next:=p3; end; > if not(bool1) and bool2 then begin p1^.next:=p2; p2^.a:=a; end; > if bool1 and not(bool2) then begin p1^.next:=p2^.next; > p1^.b:=b; end; > end > else > begin > if bool1 and bool2 then begin new(p3); p3^.next:=p2^.next; > p3^.b:=p2^.b; p3^.a:=b; p1^.b:=a; p1^.next:=p3; end; > if not(bool1) and not(bool2) then begin p1^.next:=p2^.next; > end; > if not(bool1) and bool2 then begin p2^.a:=b; p1^.next:=p2; end; > if bool1 and not(bool2) then begin p1^.b:=a; > p1^.next:=p2^.next; end; > end; > p:=4; > while (p1^.next<>nil) and (p>0) do > begin > if p1^.b=p1^.next^.a then begin p1^.b:=p1^.next^.b; > p1^.next:=p1^.next^.next; end; > p1:=p1^.next; > dec(p); > end > end; > > Procedure out; > var > p1 :repaint; > maxx,maxy :LONGINT; > begin > maxx:=line^.a; > maxy:=line^.b; > p1:=line^.next; > while p1<>nil do > begin > if (p1^.b-p1^.a)>(maxy-maxx) then begin maxx:=p1^.a; > maxy:=p1^.b; end; > p1:=p1^.next; > end; > writeln(maxx,' ',maxy); > end; > > begin > readln(n); > new(line); > line^.a:=0; line^.b:=4000; > line^.next:=nil; > for i:=1 to n do > begin > readln(s); > s1:=copy(s,1,pos(' ',s)-1); delete(s,1,pos(' ',s)); > val(s1,a,code); > s2:=copy(s,1,pos(' ',s)-1); > val(s2,b,code); > if pos('b',s)<>0 then c:='b' > else c:='w'; > work; > end; > out; > end. |