Cod sursa(job #12125)

Utilizator bigsarpeadrian bigsarpe Data 2 februarie 2007 22:19:37
Problema Triplete Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.02 kb
{$q-,r-,s-,d-,i-}
const maxn=4096;maxbuc=maxn div 16;zero=ord('0');
var t:Text;
   Pre:Array[0..1 shl 16]of longint;
   X,Y:array[0..1 shl 16]of longint;
   V:Array[0..maxn,0..maxbuc]of word;
   sol,i,j,k,n,m,maxsus:longint;s:string;
begin
   for i:=0 to 1 shl 16 do for j:=0 to 15 do inc(pre[i],(i shr j)and 1);
   assign(t,'triplete.in');reset(T);readln(t,n,m);
   maxsus:=(n-1)div 16+1;
   for i:=1 to M do
   begin
      readln(T,s);
      for j:=1 to length(s) do if s[j]=' ' then break
          else X[i]:=X[i]*10+ord(s[j])-zero;
      for k:=j+1 to length(s) do y[i]:=y[i]*10+ord(s[k])-zero;
      dec(X[i]);dec(y[i]);
      if X[i]>Y[i] then begin X[0]:=X[i];X[i]:=Y[i];Y[i]:=x[0];end;
      V[X[i],Y[i]shr 4]:=V[X[i],Y[i]shr 4]or(1 shl (Y[i]and 15));
{      V[Y[i],X[i]shr 4]:=V[Y[i],X[i]shr 4]or(1 shl (X[i]and 15));}
   end;
   close(T);
   for j:=1 to M do for i:=Y[j]shr 4 to maxsus do
      inc(sol,Pre[V[X[j],i]and V[Y[j],i]]);
   assign(T,'triplete.out');rewrite(T);writeln(T,sol);close(T);
end.