Cod sursa(job #7260)

Utilizator cimiCristina Stancu-Mara cimi Data 21 ianuarie 2007 13:15:57
Problema Diviz Scor 60
Compilator fpc Status done
Runda preONI 2007, Runda 1, Clasele 11-12 Marime 1.33 kb
const
  lim=300;
  base=30103;
var a:array [0..1,0..lim,0..lim] of longint;
  rest,p,q,m,i,j,r,n,k,s,d:longint;
  resturi:array[0..lim] of longint;
  ultap:array[0..9,1..lim] of longint;
  cif:array[1..lim]of longint;
  c:char;
  t:integer;
  sol:longint;

procedure calculez_restu;
begin
  rest:=cif[j] mod k;
  for r:=1 to (i-1) do
    rest:=(rest*10) mod k;
end;

begin
  assign(input,'diviz.in');
  reset(input);
  readln(k,s,d);
  i:=0;
  while not seekeoln do
  begin
    read(c);
    inc(i);
    val(c,cif[i],t);
    inc(a[0,i,cif[i] mod k]);
  end;
  m:=i;
  close(input);

  for i:=m downto 1 do
    for j:=0 to 9 do
      if cif[i]=j
        then ultap[j,i]:=i
        else ultap[j,i]:=ultap[j,i+1];

  p:=1;
  q:=0;
  sol:=0;
  for i:=2 to m do
  begin
    p:=1-p; {precedent}
    q:=1-q; {curent}
    fillchar(a[q],sizeof(a[q]),0);
    for j:=(m-i+1) downto 1 do
    begin
      calculez_restu;
      for t:=0 to 9 do
        if ultap[t,j+1]<>0 then
          for r:=0 to (k-1) do
                a[q,j,(r+rest) mod k]:=(a[q,j,(r+rest) mod k]+a[p,ultap[t,j+1],r])mod base;
    end;

    if (s<=i) and (i<=d) then
    begin
      for t:=1 to 9 do sol:=(sol+a[q,ultap[t,1],0]) mod base;
    end;
  end;
  assign(output,'diviz.out');
  rewrite(output);
  writeln(sol);
  close(output);
end.