Cod sursa(job #197654)

Utilizator matemariaescuMaria Mateescu matemariaescu Data 5 iulie 2008 13:24:08
Problema Grigo Scor 0
Compilator fpc Status done
Runda Junior Challenge 2008 Marime 0.88 kb
program grigo;
var n,m,i,a:longint;
    poz: array[1..100000] of byte;

function permut(n:longint):int64;
var p :int64;
    i:longint;
begin
  p:=1;
  for i:= 2 to n do
    p:=p*i;
  permut:=p;
end;

function con(a,n:longint):int64;
begin
  if n = 1 then
    con:=a
    else
      if n=a then
        con:= 1
      else
        begin
          if n=2 then
            con:=(a-1)*(a) div 2;

        end;
end;

Function calculeaza(n:longint):int64;
begin
  i:=1;
  while poz[i+1]=1 do
    inc(i);
   calculeaza:=permut(n-m)*con(n-m+i-1,i-1);
end;

begin
  assign(input,'grigo.in'); reset(input);
  assign(output,'grigo.out'); rewrite(output);
  readln(n,m);
  for i := 1 to m do
    begin
      read(a);
      poz[a]:=1;
    end;
  if (poz[1]=0) and (m<>0) then
    writeln(0)
  else
    writeln(calculeaza(n));
  close(output);
  close(input);
end.