Cod sursa(job #41652)

Utilizator andrei_infoMirestean Andrei andrei_info Data 28 martie 2007 14:15:55
Problema Matrix Scor 95
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.61 kb
//infoarena matrix 178;
const max = 1000;
var a,b:array[1..max,1..max] of char;
    t: array[0..max,0..max] of longint;
    lit: array['a'..'z'] of longint;
    rez: array[1..max,1..max] of boolean;
    n,m:integer;
    nrmat:longint;

procedure citire;
var i,j:integer;
    buf:array[1..32768] of byte;
    f:text;
begin
assign(f,'matrix.in'); reset(f); settextbuf(f,buf);
readln(f,m,n);
for i:=1 to m do
        begin
        for j:=1 to m do
                read(f,a[i,j]);
        readln(f);
        end;
for i:=1 to n do
        begin
        for j:=1 to n do
                begin
                read(f,b[i,j]);
                inc(lit[b[i,j]]);
                end;
        readln(f);
        end;
close(f);
end;

procedure calc;
var     i,j:integer;
        x:longint;
        c:char;
begin

for c:='a' to 'y'do
        begin
        fillchar(t,sizeof(t),0);
        for i:=1 to m do
                for j:=1 to m do
                        begin
                        t[i,j]:=t[i-1,j]+t[i,j-1]-t[i-1,j-1];
                        if a[i,j] = c then inc(t[i,j]);
                        end;
        for i:=n to m do
                for j:=n to m do
                        begin
                        x:=t[i,j]-t[i-n,j]-t[i,j-n]+t[i-n,j-n];
                        if x <> lit[c] then
                                rez[i,j]:=true;
                        end;
        end;
for i:=n to m do
      for j:=n to m do
           if not rez[i,j] then inc(nrmat);
end;

begin
citire;
calc;
assign(output,'matrix.out'); rewrite(output);
writeln(nrmat);
close(output);
end.