Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses
- SysUtils, Math;
- const
- p=10037;
- x:longint=257;
- type
- point=record
- x,y,n:int64;
- end;
- ap=array of point;
- var
- i,n,k,ii,j,tt:longint;
- a:array[0..2020] of point;
- h:array[0..p] of ap;
- hh,aa:int64;
- pp:point;
- f:boolean;
- function hash(s:string):int64;
- var
- i:longint;
- c:int64;
- begin
- result:=0;
- c:=1;
- for i:=1 to length(s) do begin
- c:=(c*x) mod p;
- inc(result,(ord(s[i])*c) mod p);
- result:=result mod p;
- end;
- end;
- begin
- reset(input,'input.txt');
- rewrite(output,'output.txt');
- read(n);
- for i:=1 to n do begin
- read(a[i].x,a[i].y);
- a[i].n:=i;
- tt:=a[i].x+a[i].y+int64(a[i].x)*int64(a[i].y);
- hh:=hash(inttostr(tt));
- tt:=length(h[hh]);
- setlength(h[hh],tt+1);
- h[hh][tt]:=a[i];
- end;
- for i:=1 to n do
- for j:=1 to n do begin
- if (i=47) and ((j=9) or (j=88) or (j=110)) then begin
- tt:=1;
- end;
- if (a[i].x=a[j].x) or (a[i].y=a[j].y) or
- (abs(a[i].x-a[j].x)<>abs(a[i].y-a[j].y)) then continue else begin
- f:=false;
- pp.x:=a[i].x;
- pp.y:=a[j].y;
- tt:=pp.x+pp.y+pp.x*pp.y;
- hh:=hash(inttostr(tt));
- tt:=length(h[hh]);
- dec(tt);
- for ii:=0 to tt do
- if (pp.x=h[hh][ii].x) and (pp.y=h[hh][ii].y) then begin
- f:=true;
- k:=h[hh][ii].n;
- break;
- end;
- if f then begin
- pp.x:=a[j].x;
- pp.y:=a[i].y;
- tt:=pp.x+pp.y+pp.x*pp.y;
- hh:=hash(inttostr(tt));
- tt:=length(h[hh]);
- dec(tt);
- for ii:=0 to tt do
- if (pp.x=h[hh][ii].x) and (pp.y=h[hh][ii].y) then begin
- write(a[i].n,' ',a[j].n,' ',k,' ',h[hh][ii].n);
- halt(0);
- end;
- end;
- end;
- end;
- write('NO SOLUTION');
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement