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 1203. Scientific Conference

Why wrong answer??? Sorting is simple!
Posted by TUP#1 - We hate PIBAS 13 Apr 2002 14:17
Can anyone tell us, why our program is wrong?
After sorting, this is a very simple task!
We sort intervals by Ts (if equals Ts, by Te).
Check it please!

P.S. And why judge say, that our program request 53K memory???

Andrey Popyk & Sergey Snitsar.


CONST Dim = 100007;
TYPE TLine = record L,R:integer end;

TYPE Arr = Array[1..Dim] of TLine;
VAR A:Arr;
    N,Res:longint;

PROCEDURE Shell;
var M,i,j:longint;
    P:TLine;
    bool:boolean;
begin
  M:=N;
  repeat
    M:=(M+1) div 2;
    for i:=M+1 to N do
    begin
      j:=i-M; p:=A[i]; bool:=true;
      while (j>=1) and bool do
      begin
        if (A[j].L>p.L) or (A[j].L=p.L) and (A[j].R>p.R)
          then begin A[j+M]:=A[j]; j:=j-M end
          else bool:=false
      end;
      A[j+M]:=p;
    end;
  until M=1;
end;


PROCEDURE ReadData;
var i:longint;
begin
  readln(N);
  for i:=1 to N do readln(A[i].L,A[i].R);
end;

PROCEDURE Solve;
var Curr,i:longint;
begin
  Res:=0;
  Curr:=0;
  for i:=1 to N do
    if A[i].L>Curr then begin inc(Res); Curr:=A[i].R end;
end;

BEGIN
{  assign(INPUT,'1.txt'); reset(INPUT);}
  ReadData;
  Shell;
  Solve;
  writeln(Res);
END.
Sorting isn't correct here, even more you don't need a 100,000 array (30,000 is enough :))
Posted by Miguel Angel 14 Apr 2002 10:31
> Can anyone tell us, why our program is wrong?
> After sorting, this is a very simple task!
> We sort intervals by Ts (if equals Ts, by Te).
> Check it please!
>
> P.S. And why judge say, that our program request 53K memory???
>
> Andrey Popyk & Sergey Snitsar.
>
>
> CONST Dim = 100007;
> TYPE TLine = record L,R:integer end;
>
> TYPE Arr = Array[1..Dim] of TLine;
> VAR A:Arr;
>     N,Res:longint;
>
> PROCEDURE Shell;
> var M,i,j:longint;
>     P:TLine;
>     bool:boolean;
> begin
>   M:=N;
>   repeat
>     M:=(M+1) div 2;
>     for i:=M+1 to N do
>     begin
>       j:=i-M; p:=A[i]; bool:=true;
>       while (j>=1) and bool do
>       begin
>         if (A[j].L>p.L) or (A[j].L=p.L) and (A[j].R>p.R)
>           then begin A[j+M]:=A[j]; j:=j-M end
>           else bool:=false
>       end;
>       A[j+M]:=p;
>     end;
>   until M=1;
> end;
>
>
> PROCEDURE ReadData;
> var i:longint;
> begin
>   readln(N);
>   for i:=1 to N do readln(A[i].L,A[i].R);
> end;
>
> PROCEDURE Solve;
> var Curr,i:longint;
> begin
>   Res:=0;
>   Curr:=0;
>   for i:=1 to N do
>     if A[i].L>Curr then begin inc(Res); Curr:=A[i].R end;
> end;
>
> BEGIN
> {  assign(INPUT,'1.txt'); reset(INPUT);}
>   ReadData;
>   Shell;
>   Solve;
>   writeln(Res);
> END.
>