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 1097. Square Country 2

anyone helps me plzzzz
Posted by Le Thanh Trung 13 Jan 2003 22:17
I don't know why I got WA. Can you let me see ?
Here's my source code.

type
    tab = array [1..202] of longint;

var
   E, XX, YY, Imp: array [1..100] of longint;
   n,Min,Max: longint;

   DX,DY: tab;

   X,Y: array [1..202] of longint;
   nX, nY: longint;

   Re, L, A: longint;


procedure Read_Data;
var
   i: longint;
begin
     read(L,A,n);
     Min := maxint;
     Max := 0;
     for i := 1 to n do begin
       read(Imp[i], E[i],XX[i],YY[i]);
       if Imp[i] < Min then Min := Imp[i];
       if Imp[i] > Max then Max := Imp[i];
       DX[i*2-1] := XX[i];
       DX[i*2] := XX[i]+E[i];
       DY[i*2-1] := YY[i];
       DY[i*2] := YY[i]+E[i];
     end;
     DX[2*n+1] := 1;
     DX[2*n+2] := L+1;
     DY[2*n+1] := 1;
     DY[2*n+2] := L+1;
end;


procedure QSort(l,r: integer; var A: tab);
var
   i,j: integer;
   x,k: longint;
begin
     i := l;     j := r;
     x := A[(l+r) div 2];
     repeat
       while A[i] < x do i := i + 1;
       while x < A[j] do j := j - 1;
       if i <= j then begin
         k := A[i];  A[i] := A[j];  A[j] := k;
         i := i + 1;  j := j - 1;
       end;
     until i > j;
     if i < r then QSort(i,r,A);
     if l < j then QSort(l,j,A);
end;


function Common1(x1,l1, x2,l2: longint): boolean;
begin
     Common1 := true;
     if (x1<=x2) and (x2+l2<=x1+l1) then exit;
     if (x2<=x1) and (x1+l1<=x2+l2) then exit;
     if (x2<x1) and (x1<x2+l2) then exit;
     if (x2<x1+l1) and (x1+l1<x2+l2) then exit;
     Common1 := false;
end;


function Common(x1,y1,l1, x2,y2,l2: longint): boolean;
begin
     Common := Common1(x1,l1,x2,l2) and Common1(y1,l1,y2,l2);
end;


procedure Solve;
var
   i,j,k,h: longint;
begin
     nX := 1;
     X[nX] := DX[1];
     for i := 2 to 2*n+2 do begin
       if DX[i]+A > L+1 then break;
       if DX[i] <> DX[i-1] then begin
         nX := nX+1;
         X[nX] := DX[i];
       end;
     end;

     nY := 1;
     Y[nY] := DY[1];
     for i := 2 to 2*n+2 do begin
       if DY[i]+A > L+1 then break;
       if DY[i] <> DY[i-1] then begin
         nY := nY+1;
         Y[nY] := DY[i];
       end;
     end;

     Re := maxint;
     for i := 1 to nX-1 do
       for j := 1 to nY-1 do begin
         {X[i],Y[j]  left down corner}
         h := Min;
         for k := 1 to n do
           if (h < Imp[k]) and Common(X[i],Y[j],A, XX[k],YY[k],E[k])
                then h := Imp[k];
         if h < Re then Re := h;
         if Re=Min then exit;
       end;
end;


procedure Write_Result;
begin
     if Re > 100 then writeln('IMPOSSIBLE')
       else writeln(Re);
end;


begin
     Read_Data;
     if A<L then begin
       QSort(1,2*n+2, DX);
       QSort(1,2*n+2, DY);
       Solve;
     end else Re := Max;
     Write_Result;
end.