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 do i get Wrong Answer... here is the code... if someone could test it for same cases and compare the result with those of his/hers program it would be great.
Posted by Costel::icerapper@k.ro 26 Feb 2002 12:32
program timus1019;
const
  MaxN=500{0};
  MaxM=MaxN*2+1;
  ten_9=1000000000;
  colors=['b','w'];
type
  TArt=record
             ip : longint; {initial point}
             fp : longint; {final   point}
       end;
  tv=array[1..MaxM]of TArt;
const
  sa=SizeOf(TART);
var
  n:longint;
  v:tv;
  nv:longint;
  x,y:longint;
  adding:boolean;

procedure init_st;
begin
  nv:=1;
  with v[1] do
  begin
    ip:=0;
    fp:=ten_9;
  end;
end;

procedure read_n;
begin
  readln(n);
end;

procedure read_ln;
var
  c:char;
begin
    read(x,y);
    read(c);
    while not (c in colors) do
      read(c);
    readln;
    adding:=(c='w');
end;

procedure add_tale;
begin
  inc(nv);
  with v[nv] do
  begin
    ip:=x;
    fp:=y;
  end;
end;

function GetCurrentCoord:longint;
var
  i:longint;
begin
  i:=1;
  while x>v[i].fp do
    inc(i);
  GetCurrentCoord:=i;
end;

procedure InsertBefore(k:longint);
begin
  Move(v[k],v[k+1],sa*(nv-k+1));
  with v[k] do
  begin
    ip:=x;
    fp:=y;
  end;
  inc(nv);
end;

procedure IncreaseLeft(k:longint);
begin
  v[k].ip:=x;
end;

procedure IncreaseRight(k:longint);
begin
  v[k].fp:=y;
end;

procedure add_normal;
var
  k:longint;
begin
  k:=GetCurrentCoord;
  if y<v[k].ip then
    InsertBefore(k)
  else
    if x<v[k].ip then
      IncreaseLeft(k)
    else
      if y>v[k].fp then
        IncreaseRight(k)
      else;{NOTHING}
end;

procedure add_ln;
begin
  if x>v[nv].fp then
    add_tale
  else
    if y>v[1].fp then
      add_normal
    else;{NOTHING}
end;

procedure DecreaseLeft(k:longint);
begin
  v[k].ip:=y;
end;

procedure DecreaseRight(k:longint);
begin
  v[k].fp:=x;
end;

procedure BreakInTwo(k:longint);
begin
  if k<nv then
  begin
    Move(v[k+1],v[k+2],sa*(nv-k));
  end;
  v[k+1]:=v[k];
  v[k].fp:=x;
  v[k+1].ip:=y;
  inc(nv);
end;

procedure del_normal;
var
  k:longint;
begin
  k:=GetCurrentCoord;
  if x<=v[k].ip then
    if y>v[k].ip then
      DecreaseLeft(k)
    else{NOTHING}
  else
    if y>=v[k].fp then
      DecreaseRight(k)
    else
      BreakInTwo(k);
end;

procedure del_ln;
begin
  if x>v[nv].fp then
    exit;
  del_normal;
end;

procedure delete_lines(first,last:longint);
begin
  if last<first then
    exit;
  inc(last);
  Move(v[last],v[first],sa*(nv-last+1));
  nv:=nv-(last-first);
end;

procedure delete_in_between;
var
  i1,i2:longint;
begin
  i1:=1;
  while (x>v[i1].ip)and(i1<nv) do
    inc(i1);
  i2:=i1;
  while (y>v[i2].fp)and(i2<nv) do
    inc(i2);
  dec(i2);
  delete_lines(i1,i2);
end;

procedure read_lines;
var
  i:longint;
begin
  for i:=1 to n do
  begin
    read_ln;
    delete_in_between;
    if adding then
      add_ln
    else
      del_ln;
  end;
end;

function long(i:longint):longint;
begin
  with v[i] do
    long:=fp-ip;
end;

procedure write_line;
var
  i:longint;
  k:longint;
begin
  k:=1;
  for i:=2 to nv do
    if long(i) > long(k) then
      k:=i;
  with v[k] do
    writeln(ip,' ',fp);
end;

begin
  init_st;
  read_n;
  read_lines;
  write_line;
end.