Cod sursa(job #346284)

Utilizator VmanDuta Vlad Vman Data 7 septembrie 2009 13:41:45
Problema Dreptunghiuri Scor 100
Compilator fpc Status done
Runda Lista lui wefgef Marime 1.24 kb
{$N+}
program dreptunghiuri;
var n,m,h,w,a,d,nr,delta:longint;
    s:int64;
    rad:array[0..160000]of longint;
    map:array[1..400,1..400]of word;
    f:text;
begin
assign(f,'dreptunghiuri.in');reset(f);
read(f,n,m);
close(f);
for h:=1 to m do
    rad[h*h]:=h;
{s:=((m-1)*(n-1)*m div 2)+((n-1)*(n-2) div 2)*(m-1);}
s:=(m-1)*(n-1)*(m+n-2) div 2;
for h:=2 to n-1 do
    for w:=2 to m-1 do
        if map[w][h]<>0 then s:=s+map[w][h]*(n-h)*(m-w)
           else begin
           nr:=0;
        for a:=0 to h-1 do begin
           {if (h and 1=1)and(a=h div 2+1) then begin nr:=nr*2-1;break;end
           else
               if (h and 1=0)and(a=h div 2)then nr:=nr*2-1
                  else if (h and 1=0)and(a=h div 2+1) then break;}
           d:=w*w-4*a*(h-a);
           if d<0 then begin nr:=nr*2-1;break;end
           else if (rad[d]<>0)or(d=0) then
           begin
           delta:=rad[d];
           if ((w+delta)and 1=0)and(delta<=w) then begin
              inc(nr);
              if (delta<>0)and(w>delta) then
                 inc(nr);
              end;
           end;
        end;
        map[h][w]:=nr;
        s:=s+nr*(n-h)*(m-w);
    end;
assign(f,'dreptunghiuri.out');rewrite(f);
write(f,s);
close(f);
end.