代码:

这道题也并不难,用排序+简单动规即可。因为@Kevin_Wa 大佬放的是c++,所以我来一发Pascal。

var min,max,i,a1,b1,c1,d1,n:longint;
a,b,c,d:array[0..500000] of int64;
procedure sort(l,r: longint);
var i,j,x,y,y1,y2,y3:longint;
begin
i:=l;j:=r;x:=a[(l+r) div 2];y1:=b[(l+r) div 2];
y2:=c[(l+r) div 2];y3:=d[(l+r) div 2];
repeat
 while (a[i]<x)or((a[i]=x)and(b[i]<y1))or((a[i]=x)and(b[i]=y1)and(c[i]<y2))
 or((a[i]=x)and(b[i]=y1)and(c[i]=y2)and(d[i]<y3))  do inc(i);
 while (x<a[j])or((x=a[j])and(y1<b[j]))or((x=a[j])and(y1=b[j])and(y2<c[j]))
 or((x=a[j])and(y1=b[j])and(y2=c[j])and(y3<d[j]))  do dec(j);
 if not(i>j) then
   begin
   y:=a[i];a[i]:=a[j];a[j]:=y;
   y:=b[i];b[i]:=b[j];b[j]:=y;
   y:=c[i];c[i]:=c[j];c[j]:=y;
   y:=d[i];d[i]:=d[j];d[j]:=y;
   inc(i);j:=j-1;
   end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
readln(n);
for i:=1 to n do
  begin
  read(a1,b1,c1,d1);
  a[i]:=b1-a1;b[i]:=c1-a1;c[i]:=d1-a1;
  d[i]:=i;
  end;
sort(1,n);
min:=maxlongint;
max:=-maxlongint;
for i:=2 to n do
  if (a[i]=a[i-1])and(b[i]=b[i-1])and(c[i]=c[i-1]) then
    begin
    if (d[i]-d[i-1]<min) then min:=d[i]-d[i-1];
    if (d[i]+d[i-1]>max) then max:=d[i]+d[i-1];
    end;
writeln(min,' ',max);
close(input);close(output);
end.