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 1078. Segments

i got wa!!!!!!!!!!why????????????
Posted by ruwelcome 25 Mar 2003 11:13
var
i,j,k,n,m,s,x,max,maxx:longint;
p,pp:boolean;
a,b,c,v:Array[0..500] of integer;
f:Array[0..500] of boolean;
ans:array[0..500] of integer;
money:Array[0..500] of longint;
function l(q,w:integer):longint;
begin
  l:=abs(q-w);
end;
begin
  fillchar(f,sizeof(f),true);
  readln(n);
  if n=0 then
  begin
    writeln(0);
    halt;
  end;
  if n=1 then
  begin
    writeln(1);
    writeln(1);
    halt;
  end;
  max:=-1;
  for i:=1 to n do
  v[i]:=i;
  for i:=1 to n do
  begin
    readln(a[i],b[i]);
    if a[i]>b[i] then
    begin
      m:=a[i];
      a[i]:=b[i];
      b[i]:=m;
    end;
  end;
  for i:=1 to n-1 do
    for j:=1 to n-i do
    if l(a[j],b[j])>l(a[j+1],b[j+1]) then
    begin
      x:=a[j];
      a[j]:=a[j+1];
      a[j+1]:=x;
      x:=b[j];
      b[j]:=b[j+1];
      b[j+1]:=x;
      x:=v[j];
      v[j]:=v[j+1];
      v[j+1]:=x;
    end;
    for i:=2 to n do
    begin
      if (a[i]=a[i-1]) and (b[i]=b[i-1]) then f[i]:=false;
    end;
  fillchar(money,sizeof(money),255);
  fillchar(c,sizeof(c),0);
  money[1]:=1;
  for i:=2 to n do
  if f[i] then
  begin
    p:=true;
    m:=-1;
    for j:=i-1 downto 1 do
    if f[j] then
    begin
{      if ((a[j]=a[i]) and (b[j]<b[i])) or ((a[j]>a[i]) and (b[j]=b
[i])) or ((a[j]=a[i]) and (b[j]=b[i])) then
      begin
        p:=false;
        break;
      end;}
      if (a[j]>a[i]) and (b[j]<b[i]) and (money[j]=-1) then
      begin
        p:=false;
        break;
      end;
    end;
    if p then
    begin
      for j:=i-1 downto 1 do
      if f[j] then
      begin
        if (a[j]>a[i]) and (b[j]<b[i]) then
        begin
          m:=j;
          for k:=j-1 downto 1 do
          if f[k] then
          begin
          if ((a[k]>a[i]) and (b[k]<b[i])) and ((a[k]<=a[j]) or (b[k]
>=b[j])) then
            begin
              p:=false;
              break;
            end;
          end;
          break;
        end;
      end;
    end;
    if p then
    begin
      if m=-1 then money[i]:=1;
      if m<>-1 then
      begin
        money[i]:=money[m]+1;
        c[i]:=m;
      end;
      if max<money[i] then
      begin
        max:=money[i];
        maxx:=i;
      end;
    end;
  end;
  writeln(max);
  s:=1;
  k:=maxx;
  ans[1]:=v[maxx];
  while c[k]<>0 do
  begin
    s:=s+1;
    k:=c[k];
    ans[s]:=v[k];
  end;
  for i:=s downto 1 do
  write(ans[i],' ');
  writeln;
end.