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

Why I get Wrong Answer? Who can help me?
Posted by Koala 10 Mar 2002 17:28
It is my program here. I don't know what is wrong with it.

program segment;
const
  maxn=500;
var
  c,d:array [1..maxn] of longint;
  b:array [1..maxn,1..2] of longint;
  a:array [1..maxn,1..maxn] of shortint;
  n,i,j,max,pp,mi:longint;
  procedure print(i:longint);
  var
    j:longint;
  begin
    if c[i]=0
      then write(i)
      else begin
        j:=1;
        while c[j]+1<>c[i] do inc(j);
        print(j);
        write(' ',i);
      end;
  end;
begin
  assign(input,'');
  assign(output,'');
  reset(input);
  fillchar(a,sizeof(a),0);
  fillchar(d,sizeof(d),0);
  readln(n);
  for i:=1 to n do
  begin
    readln(b[i,1],b[i,2]);
    for j:=1 to i-1 do
    begin
      if (b[j,1]<b[i,1]) and (b[j,2]>b[i,2]) then
      begin
        a[i,j]:=1;
        inc(d[j]);
      end;
      if (b[j,1]>b[i,1]) and (b[j,2]<b[i,2]) then
      begin
        a[j,i]:=1;
        inc(d[i]);
      end;
    end;
  end;
  close(input);

  fillchar(c,sizeof(c),0);
  for pp:=1 to n do
  begin
    j:=1;
    while d[j]<>0 do inc(j);
    d[j]:=-1;
    for i:=1 to n do
      if a[j,i]=1 then dec(d[i]);
    for i:=1 to n do
      if (a[i,j]=1) and (c[i]+1>c[j]) then c[j]:=c[i]+1;
  end;

  rewrite(output);
  max:=-maxlongint;
  for i:=1 to n do
    if c[i]>max then
    begin
      max:=c[i];
      mi:=i;
    end;
  writeln(max+1);
  print(mi);
  writeln;
  close(output);
end.