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

Common Board

Why did this program recievs [Restricted function]? It uses only Inc(), Dec(), Read() & Write()...
Posted by Peter Obuhov 18 Jul 2002 16:39
{problem 1116}

Const MaxSize = 64000;

Type
 TPoint = record
  X: Integer;
  Val: ShortInt;
  Num: Byte;
  Br: Char;
 end;

 TLine = record
  X1,X2: Integer;
  Val: ShortInt;
 End;

Var
 Points: Array [1..MaxSize] of TPoint;
 X0,val,x1,X2,Y,X,N: Integer;
 ResSize,Size: Word;
 Opened: Array [1..2] of Boolean;
 Res: Array [1..3200] of TLine;
 Tmp: TPoint;

Procedure QSort(L,R: Word);
Var X: Integer;
    I,J: Word;
    T: TPoint;
begin
 I:=L; J:=R; X:=Points[(I+J) div 2].X;
 Repeat
  While Points[I].x<x do Inc(I);
  While X<Points[J].x do Dec(J);
  If I<=J then
   begin
    T:=Points[I];
    Points[I]:=Points[J];
    Points[J]:=T;
    Inc(I);
    Dec(J);
   end;
 Until I>J;
 If I<R then QSort(I,r);
 If J>L then QSort(L,j);
end;

begin
 Size:=0;
 For Y:=1 to 2 do
  begin
   Read(N);
   For X:=1 to N do
    begin
     Read(X1,x2,val);
     Inc(Size);
     Points[Size].X:=X1;
     Points[Size].Val:=Val;
     Points[Size].Num:=Y;
     Points[Size].Br:='(';
     Inc(Size);
     Points[Size].X:=X2;
     Points[Size].Val:=Val;
     Points[Size].Num:=Y;
     Points[Size].Br:=')';
    end;
  end;

 QSort(1,Size);

 For Y:=1 to 3 do
  For X:=1 to Size-1 do
   If (Points[X].X=Points[X+1].X) and (Points[X].Br='(') then
    begin
     Tmp:=Points[X];
     Points[X]:=Points[X+1];
     Points[X+1]:=Tmp;
    end;

 For X:=1 to Size-1 do
  If (Points[X].X=Points[X+1].X) and (Points[X].Br=Points[X+1].Br) and
     (Points[X].Num=1) then
   begin
    Tmp:=Points[X];
    Points[X]:=Points[X+1];
    Points[X+1]:=Tmp;
   end;

 ResSize:=0;
 Opened[1]:=False; Opened[2]:=False;
 For X:=1 to Size do
  If Points[X].Br='(' then
   begin
    If (Points[X].Num=2) and (Not Opened[2]) and (Opened[1]) and (X0<>Points[X].X) then
     begin
      Inc(ResSize);
      Res[ResSize].X1:=X0;
      Res[ResSize].X2:=Points[X].X;
      Res[ResSize].Val:=Val;
     end;
    Opened[Points[X].Num]:=True;
    if Points[X].Num=1 then
     begin
      X0:=Points[X].X;
      Val:=Points[X].Val;
     end;
   end
  else
   begin
    If (Points[X].Num=1) and (Not Opened[2]) and (X0<>Points[X].X) then
     begin
      Inc(ResSize);
      Res[ResSize].X1:=X0;
      Res[ResSize].X2:=Points[X].X;
      Res[ResSize].Val:=Val;
     end;
    Opened[Points[X].Num]:=False;
    If Points[X].Num=2 then X0:=Points[X].X;
   end;
 Write(ResSize,' ');
 For X:=1 to ResSize do
  Write(Res[X].X1,' ',Res[x].x2,' ',Res[x].Val,' ');
end.
Re: Why did this program recievs [Restricted function]? It uses only Inc(), Dec(), Read() & Write()...
Posted by I am david. Tabo. 18 Jul 2002 20:08
When i saw your problem i chanje inc- +1 end dec- -1. i got accses
violation
Re: Why did this program recievs [Restricted function]? It uses only Inc(), Dec(), Read() & Write()...
Posted by Peter Obuhov 19 Jul 2002 16:57
> When i saw your problem i chanje inc- +1 end dec- -1. i got accses
> violation
Yes, there is little mistake in array sizes...
But Inc() & Dec() -- is restricted functions? Interesting... ;)
I`m VERY surprised!
Posted by Peter Obuhov 19 Jul 2002 17:31
I replaced all inc() and dec() in my program by +1 and -1,
But I got [Restricted function].

I replaced QSort( by QSort1(
But I got [Restricted function].

I was very intersted, so I began to cut some parts of my program,
and send it (program without parts). When there left only part,
that inputs data, I was VERY surprised...
Try to guess?

It got AC! Only inputing of data without any output got AC!
The inputing is very good. Where is a [descriftion function] write it.
Posted by I am david. Tabo. 20 Jul 2002 11:04
Re: The inputing is very good. Where is a [descriftion function] write it.
Posted by Peter Obuhov 20 Jul 2002 15:44
This program got [Restricted function]:


Const MaxSize = 64000;

Type
 TPoint = record
  X: Integer;
  Val: ShortInt;
  Num: Byte;
  Br: Char;
 end;

 TLine = record
  X1,X2: Integer;
  Val: ShortInt;
 End;

Var
 Points: Array [1..MaxSize] of TPoint;
 X0,val,x1,X2,Y,X,N: Integer;
 ResSize,Size: Word;
 Opened: Array [1..2] of Boolean;
 Res: Array [1..MaxSize] of TLine;
 Tmp: TPoint;

Procedure QSort1(L,R: Word);
Var X: Integer;
    I,J: Word;
    T: TPoint;
begin
 I:=L; J:=R; X:=Points[(I+J) div 2].X;
 Repeat
  While Points[I].x<x do Inc(I);
  While X<Points[J].x do Dec(J);
  If I<=J then
   begin
    T:=Points[I];
    Points[I]:=Points[J];
    Points[J]:=T;
    Inc(I);
    Dec(J);
   end;
 Until I>J;
 If I<R then QSort1(I,r);
 If J>L then QSort1(L,j);
end;

begin
 Size:=0;
 For Y:=1 to 2 do
  begin
   Read(N);
   For X:=1 to N do
    begin
     Read(X1,x2,val);
     Inc(Size);
     Points[Size].X:=X1;
     Points[Size].Val:=Val;
     Points[Size].Num:=Y;
     Points[Size].Br:='(';
     Inc(Size);
     Points[Size].X:=X2;
     Points[Size].Val:=Val;
     Points[Size].Num:=Y;
     Points[Size].Br:=')';
    end;
  end;

 QSort1(1,Size);
end.






But this got [Accepted]:

Const MaxSize = 64000;

Type
 TPoint = record
  X: Integer;
  Val: ShortInt;
  Num: Byte;
  Br: Char;
 end;

 TLine = record
  X1,X2: Integer;
  Val: ShortInt;
 End;

Var
 Points: Array [1..MaxSize] of TPoint;
 X0,val,x1,X2,Y,X,N: Integer;
 ResSize,Size: Word;
 Opened: Array [1..2] of Boolean;
 Res: Array [1..MaxSize] of TLine;
 Tmp: TPoint;

begin
 Size:=0;
 For Y:=1 to 2 do
  begin
   Read(N);
   For X:=1 to N do
    begin
     Read(X1,x2,val);
     Inc(Size);
     Points[Size].X:=X1;
     Points[Size].Val:=Val;
     Points[Size].Num:=Y;
     Points[Size].Br:='(';
     Inc(Size);
     Points[Size].X:=X2;
     Points[Size].Val:=Val;
     Points[Size].Num:=Y;
     Points[Size].Br:=')';
    end;
  end;
end.
I am very surprised. when i saw it. It got AC. See the program/
Posted by I am david. Tabo. 20 Jul 2002 21:59
Const MaxSize = 64000;

Type
 TPoint = record
  X: Integer;
  Val: ShortInt;
  Num: Byte;
  Br: Char;
 end;

 TLine = record
  X1,X2: Integer;
  Val: ShortInt;
 End;

Var
 Points: Array [1..MaxSize] of TPoint;
 X0,val,x1,X2,Y,X,N: Integer;
 ResSize,Size: Word;
 Opened: Array [1..2] of Boolean;
 Res: Array [1..MaxSize] of TLine;
 Tmp: TPoint;

begin
 Size:=0;
 For Y:=1 to 2 do
  begin
   Read(N);
   For X:=1 to N do
    begin
     Read(X1,x2,val);
     Inc(Size);
     Points[Size].X:=X1;
     Points[Size].Val:=Val;
     Points[Size].Num:=Y;
     Points[Size].Br:='(';
     Inc(Size);
     Points[Size].X:=X2;
     Points[Size].Val:=Val;
     Points[Size].Num:=Y;
     Points[Size].Br:=')';
    end;
  end;
For Y:=1 to 3 do
  For X:=1 to Size-1 do
   If (Points[X].X=Points[X+1].X) and (Points[X].Br='(') then
    begin
     Tmp:=Points[X];
     Points[X]:=Points[X+1];
     Points[X+1]:=Tmp;
    end;

 For X:=1 to Size-1 do
  If (Points[X].X=Points[X+1].X) and (Points[X].Br=Points[X+1].Br) and
     (Points[X].Num=1) then
   begin
    Tmp:=Points[X];
    Points[X]:=Points[X+1];
    Points[X+1]:=Tmp;
   end;

 ResSize:=0;
 Opened[1]:=False; Opened[2]:=False;
 For X:=1 to Size do
  If Points[X].Br='(' then
   begin
    If (Points[X].Num=2) and (Not Opened[2]) and (Opened[1]) and
(X0<>Points[X].X) then
     begin
      Inc(ResSize);
      Res[ResSize].X1:=X0;
      Res[ResSize].X2:=Points[X].X;
      Res[ResSize].Val:=Val;
     end;
    Opened[Points[X].Num]:=True;
    if Points[X].Num=1 then
     begin
      X0:=Points[X].X;
      Val:=Points[X].Val;
     end;
   end
  else
   begin
    If (Points[X].Num=1) and (Not Opened[2]) and (X0<>Points[X].X)
then
     begin
      Inc(ResSize);
      Res[ResSize].X1:=X0;
      Res[ResSize].X2:=Points[X].X;
      Res[ResSize].Val:=Val;
     end;
    Opened[Points[X].Num]:=False;
    If Points[X].Num=2 then X0:=Points[X].X;
   end;
 Write(ResSize,' ');
 For X:=1 to ResSize do
  Write(Res[X].X1,' ',Res[x].x2,' ',Res[x].Val,' ');
end.