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 I got WA? Please tell me?
Posted by Happybird 8 Jan 2003 08:10
const Max=5000;
type MyRecord=record
       start:array[1..2] of longint;
       mark:boolean;
     end;
var
  data:array[0..Max] of myRecord;
  work_data:myrecord;
  Num,total:integer;
procedure do_insert;
  var
    ins_i,ins_j:integer;
    ins_data:myrecord;
  begin
    ins_i:=-1;
    repeat
      inc(ins_i);
      if (data[ins_i].start[2]=data[ins_i+1].start[1])and(data
[ins_i].start[2]>-1) then
        data[ins_i+1].start[1]:=data[ins_i].start[1];
      if ((data[ins_i].start[1]=-1)and(data[ins_i].start[2]>-1))or
         ((data[ins_i].start[1]=data[ins_i+1].start[1])and(data
[ins_i+1].start[2]>-1)) then begin
        dec(total);
        for ins_j:=ins_i to total do data[ins_j]:=data[ins_j+1];
        data[total+1].start[1]:=-1;data[total+1].start[2]:=-1;
      end;
    until ins_i>=total;
    if work_data.mark and (work_data.start[1]>-1) then begin
      ins_j:=-1;
      repeat
        inc(ins_j);
      until (work_data.start[1]<=data[ins_j].start[1])or(ins_j>total);
      if work_data.start[1]<>data[ins_j].start[1] then begin
        inc(total);
        ins_data:=work_data;
        for ins_i:=total downto ins_j+1 do data[ins_i]:=data[ins_i-1];
        data[ins_j]:=ins_data;
      end
      else if work_data.start[2]>data[ins_j].start[2] then
        data[ins_j].start[2]:=work_data.start[2];
    end;
  end;
procedure do_work;
  var
    do_i:integer;
    this_start:longint;
  begin
    for do_i:=0 to total do begin
      if (data[do_i].start[1]=-1)or(work_data.start[1]=work_data.start
[2]) then continue;
      if work_data.mark then begin
             if data[do_i].start[2]<work_data.start[1] then continue;
             if data[do_i].start[1]>work_data.start[2] then break;
             if data[do_i].start[2]>=work_data.start[1] then begin
               if data[do_i].start[2]<=work_data.start[2] then begin
                    if data[do_i].start[1]<=work_data.start[1] then
begin
                      work_data.start[1]:=data[do_i].start[1];
                      data[do_i].start[1]:=-1;
                      continue;
                    end
                    else data[do_i].start[1]:=work_data.start[1];
                  end
               else begin
                      if data[do_i].start[1]>=work_data.start[1] then
                        data[do_i].start[1]:=work_data.start[1];
                      work_data.start[1]:=-1;
                      break;
                    end;
             end;
           end
      else begin
             if data[do_i].start[2]<work_data.start[1] then continue;
             if data[do_i].start[1]>work_data.start[2] then break;
             if data[do_i].start[2]>=work_data.start[1] then begin
                    if data[do_i].start[2]<=work_data.start[2] then
begin
                        this_start:=work_data.start[1];
                        if data[do_i].start[1]<=work_data.start[1]
then begin
                            work_data.start[1]:=data[do_i].start[2];
                            data[do_i].start[2]:=this_start;
                            continue;
                          end
                        else data[do_i].start[1]:=-1;
                        work_data.start[1]:=data[do_i].start[2];
                      end
                    else begin
                           if data[do_i].start[1]<=work_data.start[1]
then begin
                               this_start:=work_data.start[1];
                               work_data.start[1]:=work_data.start[2];
                               work_data.start[2]:=data[do_i].start
[2];
                               work_data.mark:=true;
                               if data[do_i].start[1]=this_start then
                                    data[do_i].start[1]:=-1
I have repaired my code and I got WA again,why? Please help me!
Posted by Happybird 8 Jan 2003 13:00
I have test all test data in the disscuss!!!
I have got a WA again!Why?


const Max=5000;
type MyRecord=record
       start:array[1..2] of longint;
     end;
var
  data:array[0..Max] of myRecord;
  work_data:myrecord;
  mark:boolean;
  Num,total:integer;
procedure do_insert;
  var
    ins_i,ins_j:integer;
    ins_data:myrecord;
  begin
    ins_i:=-1;
    repeat
      inc(ins_i);
      if (data[ins_i].start[2]=data[ins_i+1].start[1])and(data
[ins_i].start[2]>-1) then
        data[ins_i+1].start[1]:=data[ins_i].start[1];
      if ((data[ins_i].start[1]=-1)and(data[ins_i].start[2]>-1))or
         ((data[ins_i].start[1]=data[ins_i+1].start[1])and(data
[ins_i+1].start[2]>-1)) then begin
        dec(total);
        for ins_j:=ins_i to total do data[ins_j]:=data[ins_j+1];
        data[total+1].start[1]:=-1;data[total+1].start[2]:=-1;
      end;
    until ins_i>=total;
    if mark and (work_data.start[1]>-1) then begin
      ins_j:=-1;
      repeat
        inc(ins_j);
      until (work_data.start[1]<=data[ins_j].start[1])or(ins_j>total);
      if work_data.start[1]<>data[ins_j].start[1] then begin
        inc(total);
        ins_data:=work_data;
        for ins_i:=total downto ins_j+1 do data[ins_i]:=data[ins_i-1];
        data[ins_j]:=ins_data;
      end
      else if work_data.start[2]>data[ins_j].start[2] then
        data[ins_j].start[2]:=work_data.start[2];
    end;
  end;
procedure do_work;
  var
    do_i:integer;
    this_start:longint;
  begin
    for do_i:=0 to total do begin
      if (data[do_i].start[1]=-1)or(work_data.start[1]=work_data.start
[2]) then continue;
      if mark then begin
             if data[do_i].start[2]<work_data.start[1] then continue;
             if data[do_i].start[1]>work_data.start[2] then break;
             if data[do_i].start[2]>=work_data.start[1] then begin
               if data[do_i].start[2]<=work_data.start[2] then begin
                    if data[do_i].start[1]<=work_data.start[1] then
begin
                      work_data.start[1]:=data[do_i].start[1];
                      data[do_i].start[1]:=-1;
                      continue;
                    end
                    else data[do_i].start[1]:=work_data.start[1];
                  end
               else begin
                      if data[do_i].start[1]>=work_data.start[1] then
                        data[do_i].start[1]:=work_data.start[1];
                      work_data.start[1]:=-1;
                      break;
                    end;
             end;
           end
      else begin
             if data[do_i].start[2]<=work_data.start[1] then continue;
             if data[do_i].start[1]>=work_data.start[2] then break;
             if data[do_i].start[2]>work_data.start[1] then begin
                    if data[do_i].start[2]<=work_data.start[2] then
begin
                        this_start:=work_data.start[1];
                        if data[do_i].start[1]<=work_data.start[1]
then begin
                            work_data.start[1]:=data[do_i].start[2];
                            data[do_i].start[2]:=this_start;
                            continue;
                          end
                        else data[do_i].start[1]:=-1;
                        work_data.start[1]:=data[do_i].start[2];
                      end
                    else begin
                           if data[do_i].start[1]<=work_data.start[1]
then begin
                               this_start:=work_data.start[1];
                               work_data.start[1]:=work_data.start[2];
                               work_data.start[2]:=data[do_i].start
[2];
                               mark:=true;
                               if data[do_i].start[1]=this_start then
I Got AC, here is my Code
Posted by Locomotive 10 Jan 2003 09:16
Hi Happybird again (also in 1009)
Here is my code:

Const
  maxn                  =5001;
var
  n,i,j,t1,t2,ans1,ans2 :integer;
  a                     :array[1..maxn,1..2] of longint;
  b                     :array[0..2*maxn] of longint;
  m                     :array[1..2*maxn] of boolean;
  w                     :array[1..maxn] of boolean;
  temp                  :char;

function bs(x:longint; first,last:integer):integer;
var
  mid                 :integer;
begin
  mid:=(first+last) div 2;
  if b[mid]=x then
    bs:=mid
  else
    if x<b[mid] then
      bs:=bs(x,first,mid-1)
      else
        bs:=bs(x,mid+1,last);
end;

procedure addd(x:longint);
var
  i                   :integer;
begin
  j:=b[0];
  while x<b[j] do dec(j);
  if b[j]<>x then
  begin
    inc(b[0]);
    for i:=b[0] downto j+2 do
      b[i]:=b[i-1];
    b[j+1]:=x;
  end
end;

begin
  a[1,1]:=0;
  a[1,2]:=1000000000;
  b[0]:=1;
  b[1]:=0;
  addd(a[1,2]);
  w[1]:=true;
  readln(n);
  inc(n);
  for i:=2 to n do
  begin
    read(a[i,1],a[i,2]);
    addd(a[i,1]);
    addd(a[i,2]);
    repeat read(temp);
    until (temp='b') or (temp='w');
    w[i]:=(temp='w');
  end;
  for i:=1 to n do
  begin
    t1:=bs(a[i,1],1,b[0]);
    t2:=bs(a[i,2],1,b[0]);
    for j:=t1 to t2-1 do
      m[j]:=w[i];
  end;
  ans1:=0; ans2:=0;
  t1:=0; t2:=0;
  for i:=0 to b[0] do
    if m[i] then
      t2:=b[i+1]
    else begin
      if (t2-t1)>(ans2-ans1) then
      begin
        ans1:=t1;
        ans2:=t2;
      end;
      t1:=b[i+1];
    end;
  writeln(ans1,' ',ans2);
end.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wish it be useful for you...
i will be glad to have conversation with you more...
Yours
Aydin_n7
Help me! My program is there!
Posted by Ural_Banyan Tree 18 Jan 2003 17:14
Re: I Got AC, here is my Code
Posted by Happybird 21 Jan 2003 07:13
Thank you for your help!
I will be glad to have conversation with you more too!
but I have a bad English!
Yours
happybird
but,wrong answer
Posted by starhder 22 Apr 2003 18:53